home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / tools / zmc3v078 / zmc3v078.lzh / SRCSV078.LZH / MAKEZMD1.C < prev    next >
C/C++ Source or Header  |  2000-06-01  |  73KB  |  2,764 lines

  1. /* ==================================
  2.      ZMS->ZMD common track compile
  3.    ================================== */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <ctype.h>
  8. #include <string.h>
  9. #include <time.h>
  10. #include "switch.h"
  11. #include "parsesub.h"
  12. #include "makezmd.h"
  13. #include "etc.h"
  14. #include "68lib.h"
  15.  
  16. #include "structs.h"
  17. #include "structs2.h"
  18.  
  19. enum {
  20. #define ZMSCOMMAND(c,s) c,
  21. #include "zmscmd.h"
  22. #include "cmncmd.h"
  23. #undef ZMSCOMMAND
  24. dummy        /* it's needed for BCB */
  25. };
  26.  
  27. UBYTE *makeZmdMeter(UBYTE *zms,COMMONINF *cominf,
  28.                     TRKCHINF *trkdata, const BYTE target[]);
  29. UBYTE *makeZmdKey(UBYTE *zms,COMMONINF *cominf,
  30.                     TRKCHINF *trkdata, const BYTE target[]);
  31. UBYTE *makeZmdKey0(UBYTE *zms,int var[]);
  32. UBYTE *makeZmdSc88ModeSet(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[]);
  33. UBYTE *makeZmdXgPrint(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[]);
  34. UBYTE *makeZmdMu100VoiceMap(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[]);
  35. UBYTE *makeZmdMu100VoiceMapMain(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],const int mode);
  36. UBYTE *makeZmdGsXgDisplay(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf, const BYTE target[], int mode);
  37. UBYTE *makeZmdGmSystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
  38.                             const BYTE target[]);
  39. UBYTE *makeZmdGm2SystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
  40.                             const BYTE target[]);
  41. UBYTE *makeZmdXgSystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
  42.                             const BYTE target[]);
  43. TRKCHINF *makeZmdCommon(TRKCHINF *trkdata,UBYTE *zms, UBYTE **zms2,
  44.                         COMMONINF *cominf, const int mode);
  45. UBYTE *makeZmdGatetimeResolution(UBYTE *zms,COMMONINF *cominf,
  46.                     TRKINF *trkinf, const BYTE target[]);
  47. UBYTE *macroExclusive0(UBYTE *zms, BYTE e[], const DWORD elen,
  48.                         const char *cmnt,
  49.                         int idflag, int roland, TRKCHINF *trkdata,
  50.                         const BYTE target[]);
  51. UBYTE *macroExclusiveN(UBYTE *zms, BYTE e[], const DWORD elen,const DWORD zmdlen,
  52.                         const char *cmnt,
  53.                         int idflag,int roland, const UBYTE mdl,const int warnlvl,
  54.                         UBYTE *warn, TRKCHINF *trkdata);
  55. UBYTE *getDevice(UBYTE *zms, DWORD *ch, DWORD *chtype, COMMONINF *cominf,
  56.                     int allowALL);
  57. UBYTE *setTempo(UBYTE *zms, char *endchar,COMMONINF *cominf);
  58. UBYTE *initializeZMD(UBYTE *zms, TRKCHINF *trkdata, const char *endchar);
  59. UBYTE *setMasterClock(UBYTE *zms, const char *endchar, COMMONINF *cominf);
  60. UBYTE *getIfnoAndComment(UBYTE *zms, const char *endchar,
  61.                         DWORD *ifno, char **cmnt);
  62. UBYTE *getAssign2(UBYTE *zms, TRKCHINF *trkdata,const int trk, const char *endchar);
  63. UBYTE *makeZmdAssign(UBYTE *zms,TRKCHINF *trkdata,
  64.                         COMMONINF *cominf, BYTE *trks, const int mode);
  65. void makeZmdAssignMain(TRKCHINF *trkdata,COMMONINF *cominf,
  66.                         int trk, BYTE *trks, int ch, int chtype);
  67. UBYTE *makeZmdPlaytrk(UBYTE *zms, TRKCHINF *trkdata,
  68.                         int *stat, UBYTE **playtrk_start, int mode);
  69.  
  70.  
  71.  
  72. extern DWORD line;
  73. extern char *linebuf;
  74. extern LINEDATA *ld;
  75.  
  76. /* (BEGIN FM/ADPCMsupport by Mamiya */
  77. typedef struct {
  78.     WORD note;
  79.     WORD pitchpara;
  80.     WORD volumepara;
  81.     WORD mixdelay;
  82.     WORD mixnote;
  83.     WORD cutofs;
  84.     WORD cutsize;
  85.     BYTE revsw;
  86.     WORD fadeofs;
  87.     BYTE fadedir;
  88.     BYTE fadelevel;
  89.     WORD srcnote;
  90. } REGISTER_PCM;
  91. #ifdef A
  92. UBYTE *makeZmdCommonRegPcm(UBYTE *zms,TRKCHINF *trkdata,DWORD note, DWORD bank)
  93. {
  94.     const REGISTER_PCM initreg = {
  95.         0, -333, -333, 0,-1, 0,0, 0, 0,0,0 ,-333
  96.     };
  97.     DWORD tmpDWORD;
  98.     UBYTE *strstart;
  99.     int err, srclen;
  100.     REGISTER_PCM *rp;
  101.     rp = emalloc(sizeof(REGISTER_PCM),"rp");
  102.     *rp = initreg;    /* memcpy(rp, initreg, sizeof(REGISTER_PCM)); */
  103.     rp->note = note;
  104.     if (bank) rp->note += bank << 7;
  105.     zms = skipSpc(zms);
  106.     if (*zms == '=') zms = skipSpc(zms + 1);
  107.     if (('0' <= *zms && *zms <= '9') || *zms == '$' || *zms == '%') {
  108.         zms = getnum2(zms, &tmpDWORD, &err);
  109.         rp->srcnote = tmpDWORD;
  110.         srclen = 0;
  111.     } else if (*zms == '\"' || *zms == '\'') {
  112.         UBYTE endc;
  113.         endc = *zms++;
  114.         strstart = zms;
  115.         while (*zms >= ' ' && *zms != endc && *zms != 0xff) zms++;
  116.         srclen = zms - strstart;
  117.         if (*zms == endc) zms++;
  118.     } else {
  119.         strstart = zms;
  120.         while (*zms > ' ' && *zms != ',' && *zms != '/' && *zms != 0xff) zms++;
  121.         srclen = zms - strstart;
  122.     }
  123.     zms = skipSpc(zms);
  124.     while (1) {
  125.         if (*zms == ',') zms = skipSpc(zms + 1);
  126.         switch (*zms) {
  127.             case 'p':    case 'P':
  128.                 zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
  129.                 rp->pitchpara = tmpDWORD + 12;
  130.                 if (rp->volumepara == -333) rp->volumepara = 100;
  131.                 continue;
  132.             case 'v':    case 'V':
  133.                 zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
  134.                 rp->volumepara = tmpDWORD;
  135.                 if (rp->pitchpara == -333) rp->pitchpara = 12;
  136.                 continue;
  137.             case 'm':    case 'M':
  138.                 zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
  139.                 rp->mixnote = tmpDWORD;
  140.                 /* if (bank) rp->mixnote += bank << 7; */
  141.                 if (*zms == ',') {
  142.                     zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
  143.                     rp->mixdelay = tmpDWORD;
  144.                 }
  145.                 continue;
  146.             case 'c':    case 'C':
  147.                 zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
  148.                 rp->cutofs = tmpDWORD;
  149.                 if (*zms == ',') {
  150.                     zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
  151.                     rp->cutsize = tmpDWORD;
  152.                 }
  153.                 continue;
  154.             case 'r':    case 'R':
  155.                 rp->revsw = -1;
  156.                 zms++;
  157.                 continue;
  158.             case 'f':    case 'F':
  159.                 zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
  160.                 if (tmpDWORD < 0) {
  161.                     rp->fadeofs = -tmpDWORD;
  162.                     rp->fadedir = -1;
  163.                 } else {
  164.                     rp->fadeofs = tmpDWORD;
  165.                     rp->fadedir = 1;
  166.                 }
  167.                 if (*zms == ',') {
  168.                     zms = skipSpc(getnum2(zms + 1, &tmpDWORD, &err));
  169.                     rp->fadelevel = tmpDWORD;
  170.                 }
  171.                 continue;
  172.             default:
  173.                 break;
  174.         }
  175.         break;
  176.     }
  177.     if (rp->pitchpara == -333) rp->pitchpara = 0;
  178.     if (rp->volumepara == -333) rp->volumepara = 0;
  179.     *trkdata[0].zmd++ = 0x40;
  180.     putWord(trkdata[0].zmd, rp->note);
  181.     trkdata[0].zmd += 2;
  182.     putWord(trkdata[0].zmd, rp->pitchpara);
  183.     trkdata[0].zmd += 2;
  184.     putWord(trkdata[0].zmd, rp->volumepara);
  185.     trkdata[0].zmd += 2;
  186.     putWord(trkdata[0].zmd, rp->mixdelay);
  187.     trkdata[0].zmd += 2;
  188.     putWord(trkdata[0].zmd, rp->mixnote);
  189.     trkdata[0].zmd += 2;
  190.     putWord(trkdata[0].zmd, rp->cutofs);
  191.     trkdata[0].zmd += 2;
  192.     putWord(trkdata[0].zmd, rp->cutsize);
  193.     trkdata[0].zmd += 2;
  194.     *trkdata[0].zmd++ = rp->revsw;
  195.     putWord(trkdata[0].zmd, rp->fadeofs);
  196.     trkdata[0].zmd += 2;
  197.     *trkdata[0].zmd++ = rp->fadedir;
  198.     *trkdata[0].zmd++ = rp->fadelevel;
  199.     if (rp->srcnote != -333) {
  200.         putWord(trkdata[0].zmd, 0);
  201.         trkdata[0].zmd += 2;
  202.         putWord(trkdata[0].zmd, rp->srcnote);
  203.         trkdata[0].zmd += 2;
  204.     } else {
  205.         int i;
  206.         for (i = 0; i < srclen; i++) *trkdata[0].zmd++ = strstart[i];
  207.         *trkdata[0].zmd++ = 0;
  208.     }
  209.     efree(rp,"rp");
  210.     return zms;
  211. }
  212. /* FM/ADPCMsupport by Mamiya END) */
  213. #endif
  214.  
  215.  
  216. UBYTE *makeZmdGatetimeResolution(UBYTE *zms,COMMONINF *cominf,
  217.                     TRKINF *trkinf, const BYTE target[])
  218. {
  219.     int trk;
  220.  
  221.     for (trk = 0; target[trk] >= 0; trk++) {
  222.         DWORD var;
  223.         int err;
  224.         zms = getnum2(zms,&var,&err);
  225.         if (err) {
  226.             zmserror(".gatetime_resolution must be followed to its parameter.",line,linebuf,zms,0,1);
  227.         } else if (var < 1) {
  228.             zmserror(".gatetime_resolution parameter is out of range(8-128).",line,linebuf,zms,0,1);
  229.         }
  230.         switch (var) {
  231.             case 8: case 16: case 32: case 64:     case 128:
  232.                 break;
  233.             default:
  234.                 zmserror(".gatetime_resolution parameter is out of range(8,16,32,64,128).",line,linebuf,zms,4,1);
  235.                 break;
  236.         }
  237.  
  238.         if (target[trk] == 0) {
  239.             cominf->gtreso = var;
  240.         } else {
  241.             trkinf[target[trk]].gtreso = var;
  242.         }
  243.     }
  244.  
  245.     return zms;
  246. }
  247.  
  248.  
  249. UBYTE *makeZmdMeter(UBYTE *zms,COMMONINF *cominf,
  250.                     TRKCHINF *trkdata, const BYTE target[])
  251. {
  252.     int trk;
  253.     UBYTE *zms_ = zms;
  254.  
  255.     for (trk = 0; target[trk] >= 0; trk++) {
  256.         DWORD m, n;
  257.         int err;
  258.  
  259.         zms = getnum2(zms_, &m, &err);
  260.         /* zms = skipSpc(zms); */    /* can't use skipSpc because it skips '/' */
  261.         while (isspace(*zms)) {
  262.             zms++;
  263.         }
  264.         if (*zms++ != '/') {
  265.             zmserror("METER: illegal format. ( METER m/n )",line,linebuf,zms,0,1);
  266.         }
  267.         zms = getnum2(zms, &n, &err);
  268.  
  269.         if (target[trk] == 0) {
  270.             cominf->meter = m * 256 + n;
  271.         } else {
  272.             *trkdata[target[trk]].zmd++ = 0xC5;
  273.             *trkdata[target[trk]].zmd++ = 0x05;
  274.             *trkdata[target[trk]].zmd++ = 0x02;
  275.             *trkdata[target[trk]].zmd++ = m;
  276.             *trkdata[target[trk]].zmd++ = n;
  277.         }
  278.     }
  279.  
  280.     return zms;
  281. }
  282.  
  283.  
  284. UBYTE *makeZmdKey(UBYTE *zms,COMMONINF *cominf,
  285.                     TRKCHINF *trkdata, const BYTE target[])
  286. {
  287.     int trk;
  288.     int var[2] = { 0, 0 };
  289.  
  290.     zms = makeZmdKey0(zms, var);
  291.  
  292.     for (trk = 0; target[trk] >= 0; trk++) {
  293.         if (target[trk] == 0) {
  294.             cominf->key = var[0];
  295.             cominf->majorflag = var[1];
  296.         } else {
  297.             *trkdata[target[trk]].zmd++ = 0xC5;
  298.             *trkdata[target[trk]].zmd++ = 0x04;
  299.             *trkdata[target[trk]].zmd++ = 0x02;
  300.             *trkdata[target[trk]].zmd++ = var[0];
  301.             *trkdata[target[trk]].zmd++ = var[1];
  302.         }
  303.  
  304.     }
  305.     return zms;
  306. }
  307.  
  308.  
  309.  
  310. UBYTE *makeZmdKey0(UBYTE *zms,int var[])
  311. /* var[0] == # of #/b
  312.  * var[1] == major[0] / minor[1] / error[-1]
  313.  */
  314. {
  315.     int m = 0, n = 0;
  316.     int bracket = 0;
  317.     int flg = 1;
  318.  
  319.     zms = skipSpc(zms);
  320.     if (*zms == '{') {
  321.         bracket = 1;
  322.         zms++;
  323.     }
  324.  
  325.     do {
  326.         int i;
  327.         const char *cho="fcgdaeb-+#m";
  328.  
  329.         for (i = 0; i < (int)strlen(cho); i++) {
  330.             if (tolower(*zms) == cho[i]) {
  331.                 zms++;
  332.                 break;
  333.             }
  334.         }
  335.  
  336.         switch (i) {
  337.             case 7:        /* - */
  338.                 m -= 7;
  339.                 break;
  340.             case 8:        /* # */
  341.             case 9:        /* + */
  342.                 m += 7;
  343.                 break;
  344.             case 10:    /* m */
  345.                 flg = -1;
  346.                 break;
  347.             case 11:    /* no found */
  348.                 if (!isspace(*zms) && *zms != '/' &&
  349.                     *zms != 0x0D && *zms != 0x0A) {
  350.                     n = -1;
  351.                 }
  352.                 flg = 0;
  353.                 break;
  354.             default:    /* FCGDAEB */
  355.                 m = i - 1;
  356.                 break;
  357.         }
  358.     } while (flg > 0);
  359.  
  360.     if (!stricmp2(zms,"ajor")) {
  361.         zms += 4;
  362.     } else if (!stricmp2(zms,"inor") || flg < 0) {
  363.         m -= 3;
  364.         n = 1;
  365.         if (!stricmp2(zms,"inor")) {
  366.             zms += 4;
  367.         }
  368.     }
  369.  
  370.     zms = skipSpc(zms);
  371.     if (bracket) {
  372.         if (*zms != '}') {
  373.             zmserror("KEY: format error.",line,linebuf,zms,0,1);
  374.         } else {
  375.             zms++;
  376.         }
  377.     }
  378.  
  379.     var[0] = m;
  380.     var[1] = n;
  381.     return zms;
  382. }
  383.  
  384.  
  385.  
  386.  
  387.  
  388. UBYTE *makeZmdSc88ModeSet(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[])
  389.             /* 41 id 42 12 00 00 7f xx */
  390. {
  391.     int trk;
  392.     UBYTE *zms_ = zms;
  393.  
  394.     for (trk = 0; target[trk] >= 0; trk++) {
  395.         DWORD mode,id,ifno;
  396.         int err;
  397.         const int elen = 9;
  398.         BYTE e[9] = { 0xf0,0x41,0x10,0x42,0x12,0x00,0x00,0x7f,0x00 };
  399.         const int Trk = target[trk];
  400.         const char *p[] = {"single", "double",NULL};
  401.  
  402.         zms = getnum4(zms_,&mode,&err, p, 1);
  403.         if (err) {
  404.             zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  405.         } else if (mode < 1 && 2 < mode) {
  406.             zmserror(".SC88_MODE: the mode is out of range.",line,linebuf,zms,0,1);
  407.         }
  408.         e[8] = mode - 1;
  409.  
  410.         zms = skipchr(zms,", \t\x0d\x0a");
  411.         zms = getnum2(zms,&id,&err);
  412.         if (err < 0) {
  413.             id = 0x10;
  414.         } else if (err > 0) {
  415.             zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  416.         } else if (id < 0) {
  417.             /* It is not to be error in V2, but.... */
  418.         }
  419.         e[2] = id;
  420.  
  421.         if (Trk == 0) {        /* common trk */
  422.             zms = skipchr(zms,", \t\x0d\x0a");
  423.             zms = getnum2(zms,&ifno,&err);
  424.             if (err < 0) {
  425.                 ifno = 0xFF;
  426.             } else if (err > 0) {
  427.                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  428.             } else if (ifno < 0) {
  429.                 /* It is not to be error in V2, but.... */
  430.             }
  431.         }
  432.  
  433.         *trkdata[Trk].zmd++ = (Trk)? 0xF3 : 0x34;
  434.         *trkdata[Trk].zmd++ = (Trk)? 0x41 : ifno;
  435.         *trkdata[Trk].zmd ++ = strlen("SC88_MODE");
  436.         strncpy(trkdata[Trk].zmd, "SC88_MODE", strlen("SC88_MODE"));
  437.         trkdata[Trk].zmd += strlen("SC88_MODE");
  438.         if (Trk) {
  439.             putDword(trkdata[Trk].zmd, 4);
  440.             trkdata[Trk].zmd += 4;
  441.             memcpy(trkdata[Trk].zmd, &e[5], elen - 5);
  442.             trkdata[Trk].zmd += elen - 5;
  443.         } else {
  444.             putDword(trkdata[Trk].zmd, (elen + 2) );    /* +2: checksum,0xf7 */
  445.             trkdata[Trk].zmd += 4;
  446.             trkdata[Trk].zmd = setex(trkdata[Trk].zmd, e, elen, 1);
  447.             *trkdata[Trk].zmd++ = 0xf7;
  448.         }
  449.     }
  450.  
  451.     return zms;
  452. }
  453.  
  454.  
  455.  
  456. UBYTE *makeZmdXgPrint(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[])
  457. /* .XG_PRINT id,if str */
  458. /* $F0,$43,id,$4C,$06,$00,$00,文字列(ASCIIコード、32文字まで) ~,$F7 */
  459. {
  460.     DWORD dev, ifno = -1;
  461.     int err;
  462.     const int f0f7 = 1,roland = 3;    /* YAMAHA without checksum */
  463.     const UBYTE mdl = 0x4C;
  464.     int        elen = 3;
  465.     UBYTE e[3] = {0x06,0x00,0x00};
  466.     DWORD zmsskip;
  467.  
  468.     zms = getnum2(zms,&dev,&err);
  469.     if (err > 0) {
  470.         zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  471.     } else if (err < 0) {
  472.         dev = 0x10;
  473.     }
  474.  
  475.     zms = skipSpc(zms);
  476.     if (*zms == ',') {
  477.         zms = getnum2(++zms, &ifno,&err);
  478.         if (err < 0) {
  479.             ifno = -1;
  480.         } else if (err > 0) {
  481.             zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  482.         } else if (ifno < 0) {
  483.             /* It is not to be error in V2 */
  484.         }
  485.     }
  486.  
  487.     trkdata[0].zmd = exclusive(trkdata[0].zmd, zms, 
  488.                                 f0f7, &zmsskip,
  489.                                 ifno, "XG_PRINT",
  490.                                 roland,dev,mdl,
  491.                                 elen,e,
  492.                                 "\"","\"\x0d\x0a");
  493. /*
  494.     if (trkdata[0].zmd - ex_b0 > 3+5+3+32+1) {
  495.         zmserror("it must be under 32 characters in .xg_print.",line,linebuf,zms,2,1);
  496.     }
  497. */
  498.     zms += zmsskip;
  499.     /* cominf->z_cmn_flag |= (1 << (0x34 / 4)); */
  500.  
  501.     return zms;
  502. }
  503.  
  504.  
  505.  
  506.  
  507. UBYTE *makeZmdMu100VoiceMap(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[])
  508. {
  509.     int err;
  510.     const char *p[] = {"basic", "native",NULL};
  511.     DWORD mode;
  512.  
  513.     zms = getnum4(zms,&mode,&err, p, 0);
  514.     if (err) {
  515.         zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  516.     } else if (mode < 0 && 1 < mode) {
  517.         zmserror(".MU100_VOICE_MAP: the mode is out of range.",line,linebuf,zms,0,1);
  518.     }
  519.  
  520.     return makeZmdMu100VoiceMapMain(zms,trkdata,target,mode);
  521. }
  522.  
  523.  
  524. UBYTE *makeZmdMu100VoiceMapMain(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],const int mode)
  525. {
  526. /* .MU100_VOICE_MAP map,id,if */
  527. /* $F0,$43,id,$49,$00,$00,$12,map,$F7 */
  528.  
  529.     int elen = 8;
  530.     BYTE e[8] = { 0xf0,0x43,0x10,0x49,0x00,0x00,0x12,0x00 };
  531.     const int rolandchecksum = 0, idflag = 1;
  532.  
  533.     e[7] = mode;
  534.     zms = macroExclusive0(zms, e, elen,
  535.                             "MU100_VOICE_MAP",
  536.                             idflag,rolandchecksum, trkdata, target);
  537.     return zms;
  538. }
  539.  
  540.  
  541. UBYTE *makeZmdGsXgDisplay(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf, const BYTE target[], int mode)
  542. /* mode: 0=GS, 1=XG */
  543. {
  544.     int trk;
  545.  
  546.     for (trk = 0; target[trk] >= 0; trk++) {
  547.         DWORD    dev,ifno = -1;
  548.         int        err, j;
  549. /*        DWORD    zmsskip;
  550. */        char    *cmnt = NULL;
  551.         int        c = 0;
  552.         int        elen;
  553.         UBYTE    e[2][8 + 64];
  554.         const    UBYTE e0[8] = {0xF0,0x41,0x10,0x45,0x12,0x10,0x01,0x00};
  555.         const    UBYTE e1[7] = {0xF0,0x43,0x10,0x4C,0x07,0x00,0x00};
  556.         /*initialize; header part only */
  557.         UWORD buf[16];    /*, ebuf[64];*/
  558.  
  559.         memcpy(&e[0][0],e0,8);
  560.         memcpy(&e[1][0],e1,7);
  561.  
  562.         zms = getnum2(zms,&dev,&err);
  563.         if (err > 0) {
  564.             zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  565.         } else if (err < 0) {
  566.             dev = 0x10;
  567.         }
  568.         e[mode][2] = dev;
  569.         zms = skipSpc(zms);
  570.         if (*zms == ',') {
  571.             zms++;
  572.         }
  573.         zms = getIfnoAndComment(zms, "{",&ifno, &cmnt);
  574.         zms++;    /* { */
  575.  
  576.         while (*zms != '}') {            /* Too weak the error check is! */
  577.             DWORD tmpDWORD;
  578.  
  579.             zms = getnum2(zms,&tmpDWORD,&err);
  580.             if (!err) {
  581.                 if (c > 15) {
  582.                     zmserror("too many parameters.",line,linebuf,zms,0,1);
  583.                 }
  584.                 buf[c++] = tmpDWORD;
  585.             }
  586.             zms = skipSpcCr(zms);
  587.             if (*zms == ',') {
  588.                 zms++;
  589.             } else if (*zms == '/') {
  590.                 zms = skipComment(zms);
  591.             }
  592.         }
  593.         zms++;
  594.         if (c != 16) {
  595.             zmserror("too few parameters.",line,linebuf,zms,0,1);
  596.         }
  597.  
  598.  
  599.         if (mode == 0) {    /* GS */
  600.             int i;
  601.             elen = 8;
  602.             for (i = 3; i >= 0; i--) {
  603.                 int j;
  604.                 for (j = 0; j < 16; j++) {
  605.                     e[mode][i * 16 + j + elen] =
  606.                         (i == 3)? ((buf[j] & 1) << 4) : (buf[j] & 31);
  607.                     buf[j] >>= (i == 3)? 1 : 5;
  608.                 }
  609.             }
  610.             elen += 64;
  611.         } else {            /* XG */
  612.             int i;
  613.             elen = 7;
  614.             for (i = 2; i >= 0; i--) {
  615.                 int j;
  616.                 for (j = 0; j < 16; j++) {
  617.                     if (i != 2) {
  618.                         e[mode][i * 16 + j + elen] =
  619.                             (buf[j] >> (-(i * 7) + 9) & 0x7F);
  620.                     } else {
  621.                         e[mode][i * 16 + j + elen] =
  622.                             (buf[j] <<  ((2 * 7) - 9) & 0x7F);
  623.                     }
  624.                 }
  625.             }
  626.             elen += 48;
  627.         }
  628.  
  629.         *trkdata[0].zmd++ = 0x34;
  630.         *trkdata[0].zmd++ = ifno;            /* IF number: (-1 == current IF) */
  631.         if (cmnt) {
  632.             *trkdata[0].zmd++ = strlen(cmnt);    /* comment length */
  633.             strcpy(trkdata[0].zmd, cmnt);
  634.             trkdata[0].zmd += strlen(cmnt);
  635.         } else {
  636.             *trkdata[0].zmd++ = 0;
  637.         }
  638.  
  639.         putDword(trkdata[0].zmd, elen + 2 - mode);    /* +2: checksum,0xf7 */
  640.         trkdata[0].zmd += 4;
  641.         trkdata[0].zmd = setex(trkdata[0].zmd, &e[mode][0], elen, 1 - mode);
  642.         *trkdata[0].zmd++ = 0xf7;
  643.  
  644.         cominf->z_cmn_flag |= (1 << (0x34 / 4));
  645.         if (cmnt) {
  646.             efree(cmnt,"cmnt");
  647.         }
  648.     }
  649.  
  650.     return zms;
  651. }
  652.  
  653.  
  654.  
  655. UBYTE *makeZmdGmSystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
  656.                             const BYTE target[])
  657. {
  658. /* 18 00 06 F0 7E 7F 09 01 F7 */
  659.     const DWORD elen = 5;
  660.     BYTE e[5] = { 0xf0,0x7e,0x7f,0x09,0x01 };
  661.     const int rolandchecksum = 0;
  662.     const int idflag = 0;
  663.  
  664.     zms = macroExclusive0(zms, e, elen,
  665.                 "GM_SYSTEM_ON",
  666.                 idflag,rolandchecksum, trkdata, target);
  667.  
  668.     return zms;
  669. }
  670.  
  671.  
  672. UBYTE *makeZmdGm2SystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
  673.                             const BYTE target[])
  674. {
  675. /* 18 00 06 F0 7E 7F 09 02 F7 */
  676.     const DWORD elen = 5;
  677.     BYTE e[5] = { 0xf0,0x7e,0x7f,0x09,0x02 };
  678.     const int rolandchecksum = 0;
  679.     const int idflag = 0;
  680.  
  681.     zms = macroExclusive0(zms, e, elen,
  682.                 "GM2_SYSTEM_ON",
  683.                 idflag,rolandchecksum, trkdata, target);
  684.  
  685.     zmserror(".gm2_system_on can use only for zmc3.",line,linebuf,zms,4,1);
  686.  
  687.     return zms;
  688. }
  689.  
  690.  
  691. UBYTE *makeZmdXgSystemOn(UBYTE *zms,TRKCHINF *trkdata, COMMONINF *cominf,
  692.                             const BYTE target[])
  693. {
  694.     const DWORD elen = 8;
  695.     BYTE e[8] = { 0xf0,0x43, 0x10, 0x4c,
  696.                     0x00,0x00,0x7e,0x00 };
  697.     const int rolandchecksum = 0;
  698.     const int idflag = 1;
  699.  
  700.     zms = macroExclusive0(zms, e, elen,
  701.                             "XG_SYSTEM_ON",
  702.                             idflag,rolandchecksum, trkdata, target);
  703.     zmserror(".xg_system_on can use only for zmc2.",line,linebuf,zms,4,1);
  704.  
  705.     return zms;
  706. }
  707.  
  708.  
  709.  
  710.  
  711. TRKCHINF *makeZmdCommon(TRKCHINF *trkdata,UBYTE *zms, UBYTE **zms2,
  712.                             COMMONINF *cominf, const int mode)
  713. {
  714.     /* UBYTE *zmsbuf = zms; */
  715.     UBYTE *playtrk_start = NULL;
  716.  
  717.     int stat = 0;
  718.     BYTE trks = 0;
  719. /* (BEGIN FM/ADPCMsupport by Mamiya */
  720.     const char default_fmtone[55] = {
  721.         0,0,0,0,0, 0,0,0,0,0, 0,
  722.         0,0,0,0,0, 0,0,0,0,0, 0,
  723.         0,0,0,0,0, 0,0,0,0,0, 0,
  724.         0,0,0,0,0, 0,0,0,0,0, 0,
  725.         0,0,15,3,0,0,0,0,0,0, 0,
  726.     };
  727.     memcpy(cominf->opmtone, default_fmtone, 55);
  728.  
  729.     cominf->fmvol        = 255;
  730.     cominf->adpcmbank    = 0;
  731.     cominf->polpcm        = 0;
  732. /* FM/ADPCMsupport by Mamiya END) */
  733.  
  734. /*    linebuf = zms;*/
  735.  
  736. /*
  737.     strncpy(trkdata[0].zmd,"\x10ZmuSiC\x20",8);
  738.     trkdata[0].zmd += 8;
  739. */
  740.  
  741.  
  742.  
  743.     while (!stat) {
  744.         const DWORD bs = trkdata[0].zmd - trkdata[0].zmdbuf;
  745.  
  746.         if (bs > trkdata[0].bufsize - MTRK_OVERFLOW_RANGE) {
  747.             trkdata[0].bufsize += FIRST_MTRK_SIZE;
  748.             trkdata[0].zmdbuf = (UBYTE*)erealloc(trkdata[0].zmdbuf,sizeof(UBYTE) * trkdata[0].bufsize,"trkdata[0].zmdbuf");
  749.             trkdata[0].zmd = trkdata[0].zmdbuf + bs;
  750.         }
  751.  
  752.         zms = skipSpcCr(zms);
  753. #ifdef A
  754. /* (BEGIN FM/ADPCMsupport by Mamiya */
  755.         {
  756.             DWORD note;
  757.             int err;
  758.             zms = getnum2(zms, ¬e, &err);
  759.             if (!err) {
  760.                 zms = makeZmdCommonRegPcm(zms, trkdata, note, 0);
  761.                 continue;
  762.             } else if (err > 0) {
  763.                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  764.             }
  765.         }
  766. /* FM/ADPCMsupport by Mamiya END) */
  767. #endif
  768. /*fprintf(stderr,"(loop start)\n");*/
  769.         switch(*zms++) {
  770.             int i;
  771.  
  772.             case 0xFF:                                    /* EOF */
  773.                 stat = -1;
  774.                 *trkdata[0].zmd++ = 0xFF;
  775.                 if ((trkdata[0].zmd - trkdata[0].zmdbuf) & 1) {
  776.                     *trkdata[0].zmd++ = 0xFF;
  777.                 }
  778.                 break;
  779.             case '/':
  780.                 zms = skipComment(zms);
  781.                 break;
  782.             case '.':
  783.                 {
  784.                     const struct {
  785.                         int zmscmdcode;
  786.                         char *zmscmd;
  787.                     } comtbl1[] = {
  788. #define ZMSCOMMAND(c,s) {c, s},
  789. #include "zmscmd.h"
  790. #include "cmncmd.h"
  791. #undef ZMSCOMMAND
  792.                         {-1, NULL},
  793.                     };
  794.                     for (i = 0;;i++) {
  795.                         if (!comtbl1[i].zmscmd) break;
  796.                         if (!stricmp2(zms,comtbl1[i].zmscmd)) {
  797.                             zms += strlen(comtbl1[i].zmscmd);
  798.                             break;
  799.                         }
  800.                     }
  801.                     i = comtbl1[i].zmscmdcode;
  802.                 }
  803.  
  804.                 switch (i) {
  805. /*
  806.     ZMSCOMMAND(ZMSCMD_SC88_USER_INST,"SC88_USER_INST")
  807.     ZMSCOMMAND(ZMSCMD_SC88_USER_DRUM,"SC88_USER_DRUM")
  808.     ZMSCOMMAND(ZMSCMD_SC88_DRUM_NAME,"SC88_DRUM_NAME")
  809. */
  810.         /*OK*/        case ZMSCMD_SC88_MODE_SET:        /* ,sc88_mode_set (V3 extention) */
  811.         /*OK*/        case ZMSCMD_SC88_MODE:
  812.                         {
  813.                             const BYTE target[] = {0, -1};
  814.                             zms = makeZmdSc88ModeSet(zms, trkdata, target);
  815.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  816.                         }
  817.                         break;
  818.                     case ZMSCMD_MU100_BASIC_MAP:    /* .mu100_basic_map  (zmc2 extention) */
  819.         /*OK*/        case ZMSCMD_MU100_NATIVE_MAP:    /* .mu100_native_map (zmc2 extention) */
  820.                         {
  821.                             int mode = 0;
  822.                             const BYTE target[] = {0, -1};
  823.                             if (i == ZMSCMD_MU100_NATIVE_MAP) {
  824.                                 mode = 0x01;
  825.                                 zmserror(".mu100_native_map can use only for zmc2.",line,linebuf,zms,4,1);
  826.                             } else {
  827.                                 zmserror(".mu100_basic_map can use only for zmc2.",line,linebuf,zms,4,1);
  828.                             }
  829.                             zms = makeZmdMu100VoiceMapMain(zms,trkdata,target,mode);
  830.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  831.                         }
  832.                         break;
  833.         /*OK*/        case ZMSCMD_MU100_VOICE_MAP:            /* .mu100_voice_map (zmc3 extention) */
  834.                         {
  835.                             const BYTE target[] = {0, -1};
  836.                             zms = makeZmdMu100VoiceMap(zms,trkdata,target);
  837.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  838.                         }
  839.                         break;
  840.  
  841.     case ZMSCMD_GATETIME_RESOLUTION:
  842.         {
  843.             const BYTE target[] = {0, -1};
  844.             zms = makeZmdGatetimeResolution(zms, cominf, (TRKINF*)NULL, target);
  845.         }
  846.         break;
  847.     case ZMSCMD_METER:
  848.         {
  849.             const BYTE target[] = {0, -1};
  850.             zms = makeZmdMeter(zms, cominf, trkdata, target);
  851.         }
  852.         break;
  853.     case ZMSCMD_KEY:
  854.         {
  855.             const BYTE target[] = {0, -1};
  856.             zms = makeZmdKey(zms, cominf, trkdata, target);
  857.         }
  858.         break;
  859.  
  860.     case ZMSCMD_INCLUDE:
  861.         {
  862. #ifdef AAA
  863.             int bnest = 0;
  864.             while (*zms != 0xFF) {
  865.                 if (*zms == '{') {
  866.                     bnest++;
  867.                 } else if (*zms == '}') {
  868.                     bnest--;
  869.                     if (bnest <= 0) {
  870.                         zms++;
  871.                         break;
  872.                     }
  873.                 }            /* macro expansion is already done */
  874.                 zms++;
  875.             }
  876. #endif
  877.             zms = skipSpc(zms);
  878.             while (isgraph(*zms) && *zms != '/') {
  879.                 zms++;
  880.             }
  881. /* fprintf(stderr,"[include ned]"); */
  882.         }
  883.         break;
  884.                     case ZMSCMD_CURRENT_MIDI_OUT:
  885.                         {
  886.                             DWORD ifno;
  887.                             int err;
  888.  
  889.                             zms = getnum2(zms,&ifno,&err);
  890.                             if (err) {
  891.                                 zmserror("no IF number is specified.",line,linebuf,zms,0,1);
  892.                             } else if (ifno < 1 || 4 < ifno) {
  893.                                 zmserror("IF number must be within the range 1-4.",line,linebuf,zms,0,1);
  894.                             }
  895.                             *trkdata[0].zmd++ = 0x30;
  896.                             *trkdata[0].zmd++ = ifno - 1;
  897.                             cominf->currentmidiout = ifno;
  898.  
  899.                             cominf->z_cmn_flag |= (1 << (0x30 / 4));
  900.                         }
  901.                         break;
  902.         /*OK*/        case ZMSCMD_ASSIGN:        /* .assign  */
  903.                         {
  904.                             zms = makeZmdAssign(zms,trkdata,cominf,&trks,0);
  905. #ifdef A
  906.                             DWORD trk, ch, chtype;
  907.                             int i, err;
  908.  
  909.                             zms = skipSpc(zms);
  910.                             if (!stricmp2(zms,"tr")) {
  911.                                 zms += 2;
  912.                             }
  913.                             zms = getnum2(zms,&trk,&err);
  914.                             if (err) {
  915.                                 zmserror("no track number is specified.",line,linebuf,zms,0,1);
  916.                             } else if (trk <= 0) {
  917.                                 zmserror("illegal track number is specified.",line,linebuf,zms,0,1);
  918.                             }
  919.                             for (i = 0; i < trks; i++) {
  920.                                 if (cominf->trkassign[i] == trk) {
  921.                                     zmserror("The specified track# is already used.",line,linebuf,zms,0,1);
  922.                                 }
  923.                             }
  924.  
  925.                             zms = skipSpcCr(zms);
  926.                             if (*zms == '{' || *zms == ',') {
  927.                                 zms++;
  928.                             }
  929.                             zms = getDevice(zms,&ch, &chtype, cominf, 0);
  930. /*
  931.                             zms = skiptochr(zms,"}");
  932.                             zms++;
  933. */
  934.                             trkdata[trk].ch = trkdata[trk].ch_ = ch;
  935.                             trkdata[trk].chtype = chtype;
  936.                             cominf->trkassign[trks++] = trk;
  937.                             cominf->trkassign[trks] = -1;
  938. /* fprintf(stderr,"[%d,%d]",trk,ch); */
  939.                             zms = getAssign2(zms, trkdata, trk, "}");
  940. #endif
  941.                         }
  942.                         break;
  943.         /*OK*/        case ZMSCMD_TEMPO:            /* .tempo (V3 extention) */
  944.                         zms = setTempo(zms, NULL, cominf);
  945. /*
  946.                         zmserror(".tempo can use only on V3.",line,linebuf,zms,3,1);
  947. */
  948.                         /* cominf->z_cmn_flag |= (1 << (0x08 / 4)); */
  949.                         break;
  950.         /*OK*/        case ZMSCMD_INITIALIZE:        /* .initialize */
  951.                         zms = initializeZMD(zms, trkdata, NULL);
  952. /*
  953.                         zmserror(".initialize can use only on V3.",line,linebuf,zms,3,1);
  954. */
  955.                         cominf->z_cmn_flag |= (1 << (0x00 / 4));
  956.                         break;
  957.         /*OK*/        case ZMSCMD_MASTER_CLOCK:    /* .master_clock (V3 extention) */
  958.                         zms = setMasterClock(zms, NULL, cominf);
  959. /*
  960.                         zmserror(".master_clock can use only on V3.",line,linebuf,zms,3,1);
  961. */
  962.                         break;
  963.         /*OK*/        case ZMSCMD_YAMAHA_EXCLUSIVE:
  964.         /*OK*/        case ZMSCMD_XG_EXCLUSIVE:
  965.                     case ZMSCMD_DX_BULK_DUMP:
  966.                         {
  967.                             const UBYTE f0f7 = 1;
  968.                             UBYTE roland = 2;
  969.                             DWORD dev,mdl,ifno = -1;
  970.                             int err;
  971.                             DWORD zmsskip;
  972.                             char *cmnt = NULL;
  973.  
  974.                             if (i == ZMSCMD_DX_BULK_DUMP) {
  975.                                 roland = 4;
  976.                             } else if (i == ZMSCMD_XG_EXCLUSIVE) {
  977.                                 mdl = 0x4C;
  978.                                 roland = 3;
  979.                             } else if (ZMSCMD_YAMAHA_EXCLUSIVE) {
  980.                                 mdl = 0x43;
  981.                                 roland = 2;
  982.                             }
  983.                             zms = getnum2(zms,&dev,&err);
  984.                             if (err < 0) {
  985.                                 dev = 0x10;
  986.                                 /* mdl = 0x16; */    /* default:MT-32? */
  987.                             }
  988.  
  989.                             zms = skipSpcCr(zms);
  990.                             if (i != ZMSCMD_XG_EXCLUSIVE) {
  991.                         /*    if (i != ZMSCMD_XG_EXCLUSIVE && strchr(", \t",*zms)) { */
  992.                                 zms = getnum2(zms,&mdl,&err);
  993.                             }
  994.                             zms = skipSpcCr(zms);
  995.                             if (*zms == ',') {
  996.                                 zms++;
  997.                             }
  998.                             zms = getIfnoAndComment(zms, "{",&ifno, &cmnt);
  999.                             trkdata[0].zmd = exclusive(trkdata[0].zmd, zms, 
  1000.                                                         f0f7, &zmsskip,
  1001.                                                         ifno,cmnt,roland,dev,mdl,
  1002.                                                         0,"",
  1003.                                                         "{","}, \t\x0d\x0a");
  1004.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  1005.                             zms += zmsskip;
  1006.                             if (cmnt) {
  1007.                                 efree(cmnt,"cmnt");
  1008.                             }
  1009. /*
  1010.                             zmserror(".yamaha_exclusive can use only on V3.",line,linebuf,zms,3,1);
  1011. */
  1012.                         }
  1013.                         break;
  1014.                     case ZMSCMD_XG_EQUALIZER:
  1015.                         {
  1016.                             DWORD dev,ifno = -1;
  1017.                             int err, j;
  1018.                             DWORD zmsskip;
  1019.                             char *cmnt = NULL;
  1020.  
  1021.                             zms = getnum2(zms,&dev,&err);
  1022.                             if (err < 0) {
  1023.                                 dev = 0x10;
  1024.                             }
  1025.                             zms = skipSpc(zms);
  1026.                             if (*zms == ',') {
  1027.                                 zms++;
  1028.                             }
  1029.                             zms = getIfnoAndComment(zms, "{",&ifno, &cmnt);
  1030.                             zms++;    /* { */
  1031.                             for (j = 0; j < 6; j++) {
  1032.                                 int elen = 8;
  1033.                                 BYTE e[8] = { 0xf0,0x43,0x10,0x4C,0x02,0x40,0x00,0x00 };
  1034.                                 const UBYTE e2[] = {0x00,0x01,0x05,0x09,0x0d,0x11};
  1035.                                 const char *p[] = {"flat","jazz","pops",
  1036.                                                     "rock","crassic",NULL};
  1037.                                 const char *c[] = { "EQ TYPE", "EQ GAIN1",
  1038.                                                     "EQ GAIN2","EQ GAIN3",
  1039.                                                     "EQ GAIN4","EQ GAIN5"};
  1040.                                 DWORD para;
  1041.  
  1042.                                 if (!j) {
  1043.                                     zms = getnum4(zms,¶,&err, p, 0);
  1044.                                 } else {
  1045.                                     zms = getnum2(zms,¶,&err);
  1046.                                 }
  1047.                                 if (*zms == ',') {
  1048.                                     zms++;
  1049.                                 }
  1050.  
  1051.                                 e[2] = dev;
  1052.                                 e[6] = e2[j];
  1053.                                 e[7] = para;
  1054.  
  1055.     *trkdata[0].zmd++ = 0x34;
  1056.     *trkdata[0].zmd++ = ifno;            /* IF number: (-1 == current IF) */
  1057.     *trkdata[0].zmd++ = strlen(c[j]);    /* comment length */
  1058.     strcpy(trkdata[0].zmd, c[j]);
  1059.     trkdata[0].zmd += strlen(c[j]);
  1060.     putDword(trkdata[0].zmd, elen + 1);    /* +2: checksum,0xf7 */
  1061.     trkdata[0].zmd += 4;
  1062.     trkdata[0].zmd = setex(trkdata[0].zmd, e, elen, 0);
  1063.     *trkdata[0].zmd++ = 0xf7;
  1064.  
  1065.                             }
  1066.                             zms = skipSpc(zms);
  1067.                             if (*zms == '}') {
  1068.                                 zms++;
  1069.                             }
  1070.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  1071.                             if (cmnt) {
  1072.                                 efree(cmnt,"cmnt");
  1073.                             }
  1074.                         }
  1075.                         break;
  1076.  
  1077.         /*OK*/        case ZMSCMD_COMMENT:
  1078.                         {
  1079.                             int    cmntflg = 0;
  1080.  
  1081.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  1082.                             *trkdata[0].zmd++ = 0x40;
  1083.  
  1084.                             zms = skipSpc(zms);
  1085.                             if (*zms == '{') {
  1086.                                 cmntflg = 1;
  1087.                                 zms++;
  1088.                             }
  1089.  
  1090.                             cominf->cmnt = trkdata[0].zmd - trkdata[0].zmdbuf;
  1091.                             do {
  1092.                                 while (*zms != 0x0a && (!cmntflg || *zms != '}')) {
  1093.                                     *trkdata[0].zmd++ = *zms++;
  1094.                                 }
  1095.                                 if (!cmntflg) {
  1096.                                     *trkdata[0].zmd++ = *zms++;
  1097.                                 }
  1098. #ifdef A                        /* CR doesn't cut off on V3 */
  1099.                                 if (*(zms - 2) == 0x0d) {
  1100.                                     trkdata[0].zmd -= 2;
  1101.                                 } else if (!cmntflg) {
  1102.                                     trkdata[0].zmd -= 1;
  1103.                                 }
  1104. #endif
  1105.                                 line++;
  1106.                                 ld = incrementLine(ld);
  1107.                             } while (cmntflg && *zms != '}');
  1108.  
  1109.                             *trkdata[0].zmd++ = 0;                    /* string end code */
  1110.                             if (*zms == '}') {
  1111.                                 zms++;
  1112.                             }
  1113.                             /* printf("TITLE:%s\n",cominf->cmnt + trkdata[0].zmdbuf); */
  1114.                         }
  1115.                         break;
  1116.                     case ZMSCMD_MIDI_DATA:
  1117.         /*OK*/        case ZMSCMD_EXCLUSIVE:
  1118.                         {
  1119.                             const UBYTE f0f7 = (i == ZMSCMD_MIDI_DATA)? 0 : 1;
  1120.                             const UBYTE roland = 0;
  1121.                             DWORD zmsskip;
  1122.                             DWORD ifno = -1;
  1123.                             char *cmnt;
  1124.  
  1125.                             zms = getIfnoAndComment(zms, "{",&ifno, &cmnt);
  1126.                             trkdata[0].zmd = exclusive(trkdata[0].zmd, zms,
  1127.                                                         f0f7, &zmsskip,
  1128.                                                         ifno, cmnt,
  1129.                                                         roland,0,0,
  1130.                                                         0,"",
  1131.                                                         "{","}, \t\x0d\x0a");
  1132.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  1133.                             zms += zmsskip;
  1134.                             if (cmnt) {
  1135.                                 efree(cmnt,"cmnt");
  1136.                             }
  1137.                         }
  1138.                         break;
  1139.         /*OK*/        case ZMSCMD_ROLAND_EXCLUSIVE:
  1140.                         {
  1141.                             const UBYTE f0f7 = 1,roland = 1;
  1142.                             DWORD dev,mdl,ifno = -1;
  1143.                             int err;
  1144.                             DWORD zmsskip;
  1145.                             char *cmnt = NULL;
  1146.  
  1147.                             zms = getnum2(zms,&dev,&err);
  1148.                             if (err < 0) {
  1149.                                 dev = 0x10;
  1150.                                 mdl = 0x16;                        /* default:MT-32? */
  1151.                             }
  1152.                             if (strchr(", \t",*zms)) {
  1153.                                 zms = skipchr(zms,", \t\x0d\x0a");
  1154.                                 zms = getnum2(zms,&mdl,&err);
  1155. #ifdef AAA
  1156.                                 if (err < 0) {
  1157.                                     mdl = 0x16;                        /* default:MT-32? */
  1158.                                 }
  1159. #endif
  1160.                             }
  1161.                             zms = getIfnoAndComment(zms, "{", &ifno, &cmnt);
  1162.                             trkdata[0].zmd = exclusive(trkdata[0].zmd, zms, 
  1163.                                                         f0f7, &zmsskip,
  1164.                                                         ifno,cmnt,
  1165.                                                         roland,dev,mdl,
  1166.                                                         0,"",
  1167.                                                         "{","}, \t\x0d\x0a");
  1168.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  1169.                             zms += zmsskip;
  1170.                             if (cmnt) {
  1171.                                 efree(cmnt,"cmnt");
  1172.                             }
  1173.                         }
  1174.                         break;
  1175.                     case ZMSCMD_SC55_INIT:
  1176.                     case ZMSCMD_SC55_RESET:
  1177.                     case ZMSCMD_GS_INIT:
  1178.         /*OK*/        case ZMSCMD_GS_RESET:
  1179.                         /* 18 00 0b f0 41 10 42 12 40 00 7f 00 41 ff */
  1180.                         {
  1181.                             const DWORD elen = 9;
  1182.                             BYTE e[9] = { 0xf0,0x41,0x10,0x42,0x12,0x40,0x00,0x7f,0x00 };
  1183.                             const int rolandchecksum = 1;
  1184.                             const int idflag = 1;
  1185.                             const BYTE target[] = {0, -1};
  1186.  
  1187.                             zms = macroExclusive0(zms, e, elen,
  1188.                                         "GS_RESET",
  1189.                                         idflag,
  1190.                                         rolandchecksum, trkdata, target);
  1191.                         }
  1192.                         break;
  1193.         /*OK*/        case ZMSCMD_GM_SYSTEM_ON:
  1194.         /*OK*/        case ZMSCMD_GM2_SYSTEM_ON:
  1195.                         /* 18 00 06 F0 7E 7F 09 01 F7 */
  1196.                         {
  1197.                             const BYTE target[] = {0, -1};
  1198.                             if (i == ZMSCMD_GM_SYSTEM_ON) {
  1199.                                 zms = makeZmdGmSystemOn(zms, trkdata, cominf,
  1200.                                         target);
  1201.                             } else {
  1202.                                 zms = makeZmdGm2SystemOn(zms, trkdata, cominf,
  1203.                                         target);
  1204.                             }
  1205. #ifdef Aa
  1206.                             const DWORD elen = 5;
  1207.                             BYTE e[5] = { 0xf0,0x7e,0x7f,0x09,0x01 };
  1208.                             const int rolandchecksum = 0;
  1209.                             const int idflag = 0;
  1210.                             const BYTE target[] = {0, -1};
  1211.  
  1212.                             zms = macroExclusive0(zms, e, elen,
  1213.                                         "GM_SYSTEM_ON",
  1214.                                         idflag,rolandchecksum, trkdata, target);
  1215. #endif
  1216.                         }
  1217.                         break;
  1218.  
  1219.         /*OK*/        case ZMSCMD_XG_SYSTEM_ON:    /* zmc2 extention */
  1220.         /*OK*/        case ZMSCMD_XG_INIT:        /* zmc3 extention */
  1221.                         /* 18 00 09 F0 43 10 4C 00 00 7e 00 F7 */
  1222.                         {
  1223.                             const BYTE target[] = {0, -1};
  1224.  
  1225.                             zms = makeZmdXgSystemOn(zms, trkdata, cominf,
  1226.                                     target);
  1227. #ifdef AA
  1228.                             const DWORD elen = 8;
  1229.                             BYTE e[8] = { 0xf0,0x43, 0x10, 0x4c,
  1230.                                             0x00,0x00,0x7e,0x00 };
  1231.                             const int rolandchecksum = 0;
  1232.                             const int idflag = 1;
  1233.                             const BYTE target[] = {0,-1};
  1234.  
  1235.                             zms = macroExclusive0(zms, e, elen,
  1236.                                         "XG_SYSTEM_ON",
  1237.                                         idflag,rolandchecksum, trkdata, target);
  1238.                             zmserror(".xg_system_on can use only for zmc2.",line,linebuf,zms,4,1);
  1239. #endif
  1240.                         }
  1241.                         break;
  1242.  
  1243.                     case ZMSCMD_SC55_V_RESERVE:
  1244.                     case ZMSCMD_SC55_PARTIAL_RESERVE:
  1245.                     case ZMSCMD_GS_V_RESERVE:
  1246.                     case ZMSCMD_GS_PARTIAL_RESERVE:
  1247.                     case ZMSCMD_SC55_REVERB:
  1248.                     case ZMSCMD_GS_REVERB:
  1249.                     case ZMSCMD_SC55_CHORUS:
  1250.                     case ZMSCMD_GS_CHORUS:
  1251.                     case ZMSCMD_SC88_REVERB:
  1252.                     case ZMSCMD_SC88_CHORUS:
  1253.         /*OK*/        case ZMSCMD_SC88_DELAY:
  1254.                         /* 41 10 42 12  40 01 10 01   ... */
  1255.                         {
  1256.                             DWORD dev, ifno = -1;
  1257.                             int err;
  1258.                             const int f0f7 = 1,roland = 1;
  1259.                             const UBYTE mdl = 0x42;
  1260.                             DWORD zmsskip;
  1261.                             const int zmdlen[4] = { 29, 20+13, 21+13, 23+12 };
  1262.                             BYTE e[4][3] = { 0x40,0x01,0x10,    /* v_reserve */
  1263.                                              0x40,0x01,0x30,    /* reverb */
  1264.                                              0x40,0x01,0x38,    /* chorus */
  1265.                                              0x40,0x01,0x50 };    /* 88delay */
  1266.                             int cmd, sc88 = 0;
  1267.                             UBYTE *zmd_ = trkdata[0].zmd;
  1268.                             char *cmnt[] = {
  1269.                                 "GS_PARTIAL_RESERVE",
  1270.                                 "GS_REVERB",
  1271.                                 "GS_CHORUS",
  1272.                                 "",
  1273.                                 "SC88_REVERB",
  1274.                                 "SC88_CHORUS",
  1275.                                 "SC88_DELAY"
  1276.                             };
  1277.  
  1278.                             if (i == ZMSCMD_SC55_V_RESERVE ||
  1279.                                 i == ZMSCMD_SC55_PARTIAL_RESERVE ||
  1280.                                 i == ZMSCMD_GS_V_RESERVE ||
  1281.                                 i == ZMSCMD_GS_PARTIAL_RESERVE) {
  1282.                                 cmd = 0 ;
  1283.                             } else  if (i == ZMSCMD_SC55_REVERB ||
  1284.                                         i == ZMSCMD_GS_REVERB ||
  1285.                                         i == ZMSCMD_SC88_REVERB) {
  1286.                                 cmd = 1 ;
  1287.                             } else  if (i == ZMSCMD_SC55_CHORUS ||
  1288.                                         i == ZMSCMD_GS_CHORUS ||
  1289.                                         i == ZMSCMD_SC88_CHORUS) {
  1290.                                 cmd = 2 ;
  1291.                             } else {
  1292.                                 cmd = 3 ;
  1293.                             }
  1294.                             if (i == ZMSCMD_SC88_REVERB ||
  1295.                                 i == ZMSCMD_SC88_CHORUS ||
  1296.                                 i == ZMSCMD_SC88_DELAY) {
  1297.                                 sc88 = 1 + 2;        /* GS -> SC88 : +2 */
  1298.                             }
  1299.                             zms = getnum2(zms,&dev,&err);
  1300.                             if (err < 0) {
  1301.                                 dev = 0x10;
  1302.                             } else if (err > 0) {
  1303.                                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1304.                             } else if (dev < 0) {
  1305.                                 /* It is not to be error in V2 */
  1306.                             }
  1307.                             zms = skipSpc(zms);
  1308.                             if (*zms == ',') {
  1309.                                 zms = getnum2(++zms, &ifno,&err);
  1310.                                 if (err < 0) {
  1311.                                     ifno = -1;
  1312.                                 } else if (err > 0) {
  1313.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1314.                                 } else if (ifno < 0) {
  1315.                                     /* It is not to be error in V2 */
  1316.                                 }
  1317.                             }
  1318.  
  1319.                             trkdata[0].zmd = exclusive(trkdata[0].zmd, zms, 
  1320.                                                         f0f7, &zmsskip,
  1321.                                                         ifno,
  1322.                                                         cmnt[cmd + (sc88? 3:0)],
  1323.                                                         roland,dev,mdl,
  1324.                                                         3,e[cmd],
  1325.                                                         "{","}, \t\x0d\x0a");
  1326.                             zms += zmsskip;
  1327.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  1328.  
  1329.                             if (trkdata[0].zmd - zmd_ != zmdlen[cmd] + sc88 &&        /* non FULL parameters */
  1330.                                 (trkdata[0].zmd - zmd_ != (18 + (int)strlen(cmnt[cmd + sc88])) && cmd != 0) ) {
  1331.                                                         /* non SINGLE parameter & non vreserve */
  1332.                                 const char *warn[7] = {
  1333.                                         ".sc55_v_reserve must have just 16 parameters.",
  1334.                                         ".sc55_reverb must have 1 or 7 parameter(s).",
  1335.                                         ".sc55_chorus must have 1 or 8 parameter(s).",
  1336.                                         "",
  1337.                                         ".sc88_reverb must have 1 or 8 parameter(s).",
  1338.                                         ".sc88_chorus must have 1 or 9 parameter(s).",
  1339.                                         ".sc88_delay must have 1 or 11 parameter(s)."
  1340.                                 };
  1341. /*fprintf(stderr,"[%d]",trkdata[0].zmd - zmd_);*/
  1342.                                 zmserror(warn[cmd + sc88],line,linebuf,zms,3,1);
  1343.                             }
  1344.                             if (cmd == 0) {
  1345.                                 int i, sum = 0;
  1346.                                 UBYTE tmp = *(zmd_ + 42);
  1347.  
  1348.                                 memmove(zmd_ + 34, zmd_ + 33, 9);    /* reorder */
  1349.                                 *(zmd_ + 33) = tmp;
  1350.  
  1351.                                 zmd_ = zmd_ + 33;
  1352.                                 for (i = 0; i < 16; i++) {
  1353.                                     sum += *zmd_++;
  1354.                                 }
  1355.                                 if (sum > 24) {
  1356.                                     zmserror("voices should be less than or equal to 24 in voice-reserve.",line,linebuf,zms,3,1);
  1357.                                 }
  1358.                             }
  1359.                         }
  1360.                         break;
  1361.         /*OK*/        case ZMSCMD_SC88_EQUALIZER:
  1362.                         {
  1363.                             const DWORD elen = 3;
  1364.                             BYTE e[3] = { 0x40,0x02,0x00 };
  1365.                             const int roland = 1, idflag = 1, zmdlen = 17 + 18, mdl = 0x42;
  1366.                             const int warnlvl = 3;
  1367.  
  1368.                             zms = macroExclusiveN(zms, e, elen, zmdlen,
  1369.                                                     "SC88_EQUALIZER",
  1370.                                                     idflag,roland, mdl,warnlvl,
  1371.                                                     ".sc88_equalizer must have just 4 parameters.",
  1372.                                                     trkdata);
  1373.                             /* zmserror(".sc88_equalizer can use only on V3.",line,linebuf,zms,3,1); */
  1374.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  1375.                         }
  1376.                         break;
  1377.  
  1378.                     case ZMSCMD_SC55_PART_SETUP:
  1379.                     case ZMSCMD_SC55_PART_PARAMETER:
  1380.                     case ZMSCMD_GS_PART_SETUP:
  1381.                     case ZMSCMD_GS_PART_PARAMETER:
  1382.                     case ZMSCMD_SC88_PART_SETUP:
  1383.         /*OK*/        case ZMSCMD_SC88_PART_PARAMETER:
  1384.                         {
  1385.                             const UBYTE f0f7 = 1,roland = 1;
  1386.                             const UBYTE mdl= 0x42;
  1387.                             DWORD dev, ifno;
  1388.                             int err;
  1389.                             DWORD zmsskip,part;
  1390.                             const DWORD elen = 3;
  1391.                             BYTE e[3] = { 0x40,0x10,0x02 };
  1392.                             int cmd = (i == ZMSCMD_SC88_PART_SETUP ||
  1393.                                         i == ZMSCMD_SC88_PART_PARAMETER)?
  1394.                                         1 : 0;
  1395.                             int paras = (cmd == 1)? 127 : 119;
  1396.                             UBYTE *zmd_ = trkdata[0].zmd;
  1397.                             char *cmnt[] = {"GS_PART_SETUP","SC88_PART_SETUP"};
  1398.  
  1399.                             zms = getnum2(zms,&part,&err);
  1400.                             if (err) {
  1401.                                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1402.                             }
  1403.                             zms = getnum2(zms,&dev,&err);
  1404.                             if (err == -1) {
  1405.                                 dev = 0x10;
  1406.                             } else if (err > 0) {
  1407.                                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1408.                             } else if (dev < 0) {
  1409.                                 /* It is not to be error in V2, but.... */
  1410.                             }
  1411.                             if (part == 10) {
  1412.                                 part = 0;
  1413.                             } else if (part > 10) {
  1414.                                 part--;
  1415.                             }
  1416.                             e[2] = 0x10 + part;
  1417.                             zms = skipSpc(zms);
  1418.                             if (*zms == ',') {
  1419.                                 zms = getnum2(++zms, &ifno,&err);
  1420.                                 if (err < 0) {
  1421.                                     ifno = -1;
  1422.                                 } else if (err > 0) {
  1423.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1424.                                 } else if (ifno < 0) {
  1425.                                     /* It is not to be error in V2 */
  1426.                                 }
  1427.                             }
  1428.                             trkdata[0].zmd = exclusive(trkdata[0].zmd, zms, 
  1429.                                                         f0f7, &zmsskip,
  1430.                                                         ifno,cmnt[cmd],
  1431.                                                         roland,dev,mdl,
  1432.                                                         elen,e,
  1433.                                                         "{","}, \t\x0d\x0a");
  1434. #ifdef AAA
  1435.                             if (trkdata[0].zmd - zmd_ > 13 + paras) {        /* non FULL parameters */
  1436.                             /* 18 ll ll f0 41 10 42 12 40 1x 02 n1 n2 ... x127 sum f7 */
  1437.                                 if (paras == 119) {
  1438.                                     zmserror(".sc55_part_setup: too many parameters.",line,linebuf,zms,2,1);
  1439.                                 } else {
  1440.                                     zmserror(".sc88_part_setup: too many parameters.",line,linebuf,zms,3,1);
  1441.                                 }
  1442.                             }
  1443. #endif
  1444.                             zms += zmsskip;
  1445.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  1446.                         }
  1447.                         break;
  1448.                     case ZMSCMD_SC55_DRUM_SETUP:
  1449.                     case ZMSCMD_GS_DRUM_SETUP:
  1450.                     case ZMSCMD_SC88_DRUM_SETUP:
  1451.                         {
  1452.                             DWORD map,key,id,ifno = -1;
  1453.                             int j,err;
  1454.                             const int elen = 9;
  1455.                             BYTE e[9] = { 0xf0,0x41,0x10,0x42,0x12,0x41,0x00,0x00,0x00 };
  1456.                             int paras = (i == ZMSCMD_SC88_DRUM_SETUP)? 9 : 8;
  1457.  
  1458.                             zms = getnum2(zms,&map,&err);
  1459.                             if (err) {
  1460.                                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1461.                             }
  1462.                             zms = skipchr(zms,", \t\x0d\x0a");
  1463.                             zms = getnum2(zms,&key,&err);
  1464.                             if (err) {
  1465.                                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1466.                             }
  1467.                             zms = skipchr(zms,", \t\x0d\x0a");
  1468.                             zms = getnum2(zms,&id,&err);
  1469.                             if (err == -1) {
  1470.                                 id = 0x10;
  1471.                             } else if (err > 0) {
  1472.                                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1473.                             } else if (id < 0) {
  1474.                                 /* It is not to be error in V2, but.... */
  1475.                             }
  1476.                             e[2] = id;
  1477.  
  1478.                             zms = skipSpc(zms);
  1479.                             if (*zms == ',') {
  1480.                                 zms = getnum2(++zms, &ifno,&err);
  1481.                                 if (err < 0) {
  1482.                                     ifno = -1;
  1483.                                 } else if (err > 0) {
  1484.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1485.                                 } else if (ifno < 0) {
  1486.                                     /* It is not to be error in V2 */
  1487.                                 }
  1488.                             }
  1489.  
  1490.                             *trkdata[0].zmd++ = 0x34;
  1491.                             *trkdata[0].zmd++ = ifno;
  1492.                             *trkdata[0].zmd++ = 0;        /* comment */
  1493.                             putDword(trkdata[0].zmd, (elen + 2) * paras);    /* +2: checksum,0xf7 */
  1494.                             trkdata[0].zmd += 4;
  1495.  
  1496.                             zms = skiptochr(zms,"{");
  1497.                             zms++;
  1498.                             for (j = 0; j < paras; j++) {
  1499.                                 DWORD var;
  1500.                                 zms = getnum2(zms,&var,&err);
  1501.                                 if (err) {
  1502.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1503.                                 }
  1504.                                 /* e[0] = 0x41; */
  1505.                                 e[6] = (map << 4) + (j + 1);
  1506.                                 e[7] = key;
  1507.                                 e[8] = var;
  1508.                                 trkdata[0].zmd = setex(trkdata[0].zmd, e, elen, 1);
  1509.                                 *trkdata[0].zmd++ = 0xf7;
  1510.                                 zms = skipchr(zms,", \t\x0d\x0a");
  1511.                             }
  1512.                             zms = skiptochr(zms,"}");
  1513.                             zms++;
  1514.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  1515.                         }
  1516.                         break;
  1517.                     case ZMSCMD_SC55_PRINT:
  1518.                     case ZMSCMD_GS_PRINT:
  1519.                         {
  1520.                             DWORD dev, ifno = -1;
  1521.                             int err;
  1522.                             const int f0f7 = 1,roland = 1;
  1523.                             const UBYTE mdl = 0x45;
  1524.                             int        elen = 3;
  1525.                             UBYTE e[3] = {0x10,0x00,0x00};
  1526.                             DWORD zmsskip;
  1527.  
  1528.                             zms = getnum2(zms,&dev,&err);
  1529.                             if (err > 0) {
  1530.                                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1531.                             } else if (err < 0) {
  1532.                                 dev = 0x10;
  1533.                             }
  1534.  
  1535.                             zms = skipSpc(zms);
  1536.                             if (*zms == ',') {
  1537.                                 zms = getnum2(++zms, &ifno,&err);
  1538.                                 if (err < 0) {
  1539.                                     ifno = -1;
  1540.                                 } else if (err > 0) {
  1541.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1542.                                 } else if (ifno < 0) {
  1543.                                     /* It is not to be error in V2 */
  1544.                                 }
  1545.                             }
  1546.  
  1547.  
  1548.                             trkdata[0].zmd = exclusive(trkdata[0].zmd, zms, 
  1549.                                                         f0f7, &zmsskip,
  1550.                                                         ifno, "GS_PRINT",
  1551.                                                         roland,dev,mdl,
  1552.                                                         elen,e,
  1553.                                                         "\"","\"\x0d\x0a");
  1554. /*
  1555.                             if (trkdata[0].zmd - ex_b0 > 3+5+3+32+1) {
  1556.                                 zmserror("it must be under 32 characters in .sc55_print.",line,linebuf,zms,2,1);
  1557.                             }
  1558. */
  1559.                             zms += zmsskip;
  1560.                             cominf->z_cmn_flag |= (1 << (0x34 / 4));
  1561.                         }
  1562.                         break;
  1563.                     case ZMSCMD_XG_PRINT:
  1564.                         {
  1565.                             const BYTE target[] = { 0, -1 };
  1566.                             zms = makeZmdXgPrint(zms, trkdata, target);
  1567.                         }
  1568.                         break;
  1569.  
  1570.                     case ZMSCMD_SC55_DISPLAY:
  1571.                     case ZMSCMD_GS_DISPLAY:
  1572.                         {
  1573.                             const BYTE target[] = { 0, -1 };
  1574.                             zms = makeZmdGsXgDisplay(zms, trkdata, cominf, target, 0);
  1575.                         }
  1576.                         break;
  1577.                     case ZMSCMD_XG_DISPLAY:        /* zmc3 extention */
  1578.                         {
  1579.                             const BYTE target[] = { 0, -1 };
  1580.                             zms = makeZmdGsXgDisplay(zms, trkdata, cominf, target, 1);
  1581.                         }
  1582.                         break;
  1583.  
  1584.  
  1585.  
  1586.  
  1587.                     case ZMSCMD_WAVE_FORM:
  1588.                         /* 0x4a, size(.w), no(.b).looptype(.b),looppoint(.w),data(.w),.. */
  1589.                         {
  1590.                             DWORD waveno,looptype = 0,ls = 0,num = 0;
  1591.                             DWORD le = -1, lt = 0;
  1592.                             char *cmnt = NULL;
  1593.                             UBYTE *ws = trkdata[0].zmd + 3;
  1594.                             int err;
  1595.  
  1596.                             zms = getnum2(zms,&waveno,&err);
  1597.                             if (err) {
  1598.                                 zmserror("wave# is not specified.",line,linebuf,zms,0,1);
  1599.                             }
  1600.                             zms = skipSpcCr(zms);
  1601.                             if (*zms == ',') {
  1602.                                 zms++;
  1603.                             }
  1604.                             {
  1605.                                 const char *p[] = {"1shot", "repeat", "alternate",NULL};
  1606.                                 zms = getnum4(zms,&looptype,&err, p, 0);
  1607.                                 if (err) {
  1608.                                     zmserror("looptype is not specified.",line,linebuf,zms,0,1);
  1609.                                 }
  1610.                             }
  1611.                             zms = skipSpcCr(zms);
  1612.                             if (*zms == ',') {
  1613.                                 zms++;
  1614.                             }
  1615.                             {
  1616.                                 zms = getnum2(zms,&ls,&err);
  1617. /*
  1618.                                 if (err) {
  1619.                                     zmserror("looppoint is not specified.",line,linebuf,zms,2,1);
  1620.                                 }
  1621. */
  1622.                             }
  1623.                             zms = skipSpcCr(zms);
  1624.                             if (*zms == ',') {
  1625.                                 zms++;
  1626.                             }
  1627.                             {
  1628.                                 zms = getnum2(zms,&le,&err);
  1629.                                 if (err < 0) {
  1630.                                     le = -1;
  1631.                                 }
  1632. /*
  1633.                                 if (err) {
  1634.                                     zmserror("looppoint is not specified.",line,linebuf,zms,2,1);
  1635.                                 }
  1636. */
  1637.                             }
  1638.                             zms = getIfnoAndComment(zms, "{", <, &cmnt);
  1639.                             if (lt < 0) {
  1640.                                 lt = 0;
  1641.                             }
  1642.  
  1643.                             cominf->z_cmn_flag |= (1 << (0x1c / 4));
  1644.                             *trkdata[0].zmd++ = 0x1c;
  1645.                             putWord(trkdata[0].zmd, waveno);
  1646.                             trkdata[0].zmd += 2;
  1647.  
  1648.                             trkdata[0].zmd += 4;            /* size will be set */
  1649.  
  1650.                             *trkdata[0].zmd++ = looptype;
  1651.                             putDword(trkdata[0].zmd,ls * 2);
  1652.                             trkdata[0].zmd += 4;
  1653.                             putDword(trkdata[0].zmd,le * 2 + 2);
  1654.                             trkdata[0].zmd += 4;
  1655.                             putDword(trkdata[0].zmd,lt);
  1656.                             trkdata[0].zmd += 4;
  1657.                             putDword(trkdata[0].zmd,0);
  1658.                             trkdata[0].zmd += 4;
  1659.  
  1660.                             if (cmnt) {
  1661.                                 *trkdata[0].zmd++ = strlen(cmnt);
  1662.                                 strcpy(trkdata[0].zmd, cmnt);
  1663.                                 trkdata[0].zmd += strlen(cmnt);
  1664.                             } else {
  1665.                                 *trkdata[0].zmd++ = 0;
  1666.                             }
  1667.                             if ((trkdata[0].zmd - trkdata[0].zmdbuf) & 1) {
  1668.                                 *trkdata[0].zmd++ = 0;
  1669.                             }
  1670.  
  1671.                             zms--;
  1672.                             do {
  1673.                                 zms = skipSpcCr(zms + 1);
  1674.                             } while (*zms == '=');
  1675.                             if (*zms != '{') {
  1676.                                 zmserror("wave definition error.",line,linebuf,zms,0,1);
  1677.                             }
  1678.                             zms++;
  1679.  
  1680.                             while (*zms != '}') {            /* Too weak the error check is! */
  1681.                                 DWORD tmpDWORD;
  1682.  
  1683.                                 zms = getnum2(zms,&tmpDWORD,&err);
  1684.                                 if (!err) {
  1685.                                     putWord(trkdata[0].zmd, tmpDWORD);
  1686.                                     trkdata[0].zmd += 2;
  1687.                                     num++;
  1688.                                 }
  1689.                                 zms = skipSpcCr(zms);
  1690.                                 if (*zms == ',') {
  1691.                                     zms++;
  1692.                                 } else if (*zms == '/') {
  1693.                                     zms = skipComment(zms);
  1694.                                 }
  1695.                             }
  1696.                             zms++;
  1697.                             putDword(ws,num * 2);
  1698.                             if (le < 0) {
  1699.                                 putDword(ws + 9, num * 2);
  1700.                             }
  1701.                             if (cmnt) {
  1702.                                 efree(cmnt,"cmnt");
  1703.                             }
  1704.                         }
  1705.                         break;
  1706.                     case ZMSCMD_RANDOMIZE_SEED:    /* zmc2 extention */
  1707.                         {
  1708.                             DWORD seed;
  1709.                             int err;
  1710.  
  1711.                             zms = skipSpcCr(zms);
  1712.                             zms = getnum2(zms,&seed,&err);
  1713.                             if (err) {
  1714.                                 srand(time(NULL));
  1715.                                 /* zmserror("random_seed error.",line,linebuf,zms,0,1); */
  1716.                             } else {
  1717.                                 srand(seed);
  1718.                             }
  1719.                             zmserror(".randomize_seed can use only for zmc2.",line,linebuf,zms,4,1);
  1720.                         }
  1721.                         break;
  1722.                     case ZMSCMD_LEGACY_1CLOCK_TIE:    /* zmc2 extention */
  1723.                         {
  1724.                             DWORD tie;
  1725.                             int err;
  1726.  
  1727.                             zms = getnum2(zms,&tie,&err);
  1728.                             if (err) {
  1729.                                 cominf->l1tie = 1;
  1730.                             } else {
  1731.                                 cominf->l1tie = tie;
  1732.                             }
  1733.                             zmserror(".legacy_*1_tie can use only for zmc2.",line,linebuf,zms,4,1);
  1734.                         };
  1735.                         break;
  1736.                     case ZMSCMD_DEFINE:    /* V3 extention */
  1737.                         {
  1738.                             int bnest = 0;
  1739.                             while (*zms != 0xFF) {
  1740.                                 if (*zms == '{') {
  1741.                                     bnest++;
  1742.                                 } else if (*zms == '}') {
  1743.                                     bnest--;
  1744.                                     if (bnest <= 0) {
  1745.                                         zms++;
  1746.                                         break;
  1747.                                     }
  1748.                                 }            /* macro expansion is already done */
  1749.                                 zms++;
  1750.                             }
  1751.                         }
  1752. /*
  1753.                         zmserror(".define can use only on V3.",line,linebuf,zms,3,1);
  1754. */
  1755.                         break;
  1756.                     case ZMSCMD_LENGTH_MODE:    /* V3 extention */
  1757.                         zms = skipLine(zms);
  1758.                         break;
  1759.                     case ZMSCMD_TRACK:    /* V3 extention */
  1760.                         zms = makeZmdPlaytrk(zms, trkdata, &stat, &playtrk_start, 0);
  1761. #ifdef A
  1762.                         stat = 1;
  1763.                         *trkdata[0].zmd++ = 0xFF;
  1764.                         if ((trkdata[0].zmd - trkdata[0].zmdbuf) & 1) {
  1765.                             *trkdata[0].zmd++ = 0xFF;
  1766.                         }
  1767.                         while ( *zms != '.' ) {            /* '('まで戻す */
  1768.                             zms--;
  1769.                         }
  1770.                         if (!playtrk_start) {
  1771.                             playtrk_start = zms;
  1772.                         }
  1773.                         /* zms = skipLine(zms); */    /* del v0.71 */
  1774. #endif
  1775.                         break;
  1776.  
  1777. /* (BEGIN FM/ADPCMsupport by Mamiya */
  1778. #ifdef AAA
  1779.                     case ZMSCMD_MIDI_DUMP:
  1780.                     case ZMSCMD_ADPCM_BLOCK_DATA:
  1781.                     case ZMSCMD_ADPCM_LIST:
  1782.                         {
  1783.                             UBYTE    *strstart;
  1784.                             BYTE    cr;
  1785.                             int        len;
  1786.                             if (i == ZMSCMD_MIDI_DUMP) {
  1787.                                 *trkdata[0].zmd++ = 0x62;
  1788.                             } else if (i == ZMSCMD_ADPCM_BLOCK_DATA) {
  1789.                                 *trkdata[0].zmd++ = 0x63;
  1790.                             } else if (i == ZMSCMD_ADPCM_LIST) {
  1791.                                 *trkdata[0].zmd++ = 0x60;
  1792.                             }
  1793.                             zms = skipSpc(zms);
  1794.                             if (*zms == '=') zms = skipSpc(zms + 1);
  1795.                             strstart = zms;
  1796.                             zms = skipComment(zms);
  1797.                             if (*(zms - 1) == 0x0a && *(zms - 2) == 0x0d) {
  1798.                                 cr = 2;
  1799.                             } else {
  1800.                                 cr = 1;
  1801.                             }
  1802.                             len = zms - cr - strstart;
  1803.                             if (getSwitchVal('z') > 1) {
  1804.                                 int i;
  1805.                                 UBYTE c = 0;
  1806.                                 for (i = 0; i < len; i++) {
  1807.                                     if (c & 0x80)
  1808.                                         c = strstart[i];
  1809.                                     else if (isalpha(strstart[i]))
  1810.                                         c = toupper(strstart[i]);
  1811.                                     else if (strstart[i] <= ' ')
  1812.                                         break;
  1813.                                     else
  1814.                                         c = strstart[i];
  1815.                                     *trkdata[0].zmd++ = c;
  1816.                                 }
  1817.                             } else {
  1818.                                 strncpy(trkdata[0].zmd, strstart, len);
  1819.                                 trkdata[0].zmd += len;
  1820.                             }
  1821.                             *trkdata[0].zmd++ = 0;
  1822.                         }
  1823.                         break;
  1824.                     case ZMSCMD_FM_VSET:
  1825.                         {
  1826.                             DWORD dat;
  1827.                             int err, i;
  1828.                             zms = skipSpcCr(getnum2(zms,&dat,&err));
  1829.                             if (*zms == '=') zms = skipSpcCr(zms + 1);
  1830.                             if (err < 0 || *zms != '{') {
  1831.                                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1832.                             }
  1833.                             zms++;
  1834.                             memcpy(cominf->opmtone + 55 - 9, default_fmtone + 55 - 9, 9);
  1835.                             *trkdata[0].zmd++ = 0x1B;
  1836.                             *trkdata[0].zmd++ = dat;
  1837.                             for (i = 0 ; i < 55 ; i++) {
  1838.                                 zms = skipchr(zms," ,\t");
  1839.                                 zms = getnum2(zms,&dat,&err);
  1840.                                 if (err < 0) break;
  1841.                                 cominf->opmtone[i] = dat;
  1842.                             }
  1843.                             memcpy(trkdata[0].zmd, cominf->opmtone, 55);
  1844.                             trkdata[0].zmd += 55;
  1845.                             zms = skipSpcCr(zms);
  1846.                             if (*zms != '}') {
  1847.                                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1848.                             }
  1849.                             zms++;
  1850.                         }
  1851.                         break;
  1852.                     case ZMSCMD_ADPCM_BANK:
  1853.                         {
  1854.                             DWORD v;
  1855.                             int err;
  1856.                             zms = skipSpc(zms);
  1857.                             if (*zms == '=') zms = skipSpc(zms + 1);
  1858.                             zms = getnum2(zms, &v, &err);
  1859.                             if (err) {
  1860.                                 zmserror("adpcm_bank must be followed to its parameter.",line,linebuf,zms,0,1);
  1861.                             } else if (v < 1 || 4 < v) {
  1862.                                 zmserror("adpcm_bank parameter is out of range(1-4).",line,linebuf,zms,0,1);
  1863.                             } else {
  1864.                                 cominf->adpcmbank = v - 1;
  1865.                             }
  1866.                         }
  1867.                         break;
  1868.                     case ZMSCMD_FM_MASTER_VOLUME:
  1869.                         {
  1870.                             DWORD v;
  1871.                             int err;
  1872.                             zms = skipSpc(zms);
  1873.                             if (*zms == '=') zms = skipSpc(zms + 1);
  1874.                             zms = getnum2(zms, &v, &err);
  1875.                             if (err) {
  1876.                                 zmserror("fm_master_volume must be followed to its parameter.",line,linebuf,zms,0,1);
  1877.                             } else if (v < 0 || 255 < v) {
  1878.                                 zmserror("fm_master_volume parameter is out of range(0-255).",line,linebuf,zms,0,1);
  1879.                             } else {
  1880.                                 cominf->fmvol = v;
  1881.                             }
  1882.                         }
  1883.                         break;
  1884.                     case ZMSCMD_ERASE:
  1885.                         {
  1886.                             DWORD v;
  1887.                             int err;
  1888.                             zms = skipSpc(zms);
  1889.                             if (*zms == '.') zms = skipSpc(zms + 1);
  1890.                             if (*zms == 'o' || *zms == 'O') {
  1891.                                 UBYTE note;
  1892.                                 zms = skipSpc(getnum2(zms + 1, &v, &err));
  1893.                                 note = *zms | 0x20;
  1894.                                 if (note < 'a' || 'g' < note) {
  1895.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1896.                                 }
  1897.                                 do {
  1898.                                     zms = skipSpc(zms + 1);
  1899.                                 } while (*zms == '+' || *zms == '#' || *zms == '-');
  1900.                             } else {
  1901.                                 zms = getnum2(zms, &v, &err);
  1902.                             }
  1903.                         }
  1904.                         break;
  1905.                     case ZMSCMD_O:
  1906.                         {
  1907.                             const BYTE ntbl[] = {9,11,0,2,4,5,7};
  1908.                             DWORD oct;
  1909.                             UBYTE note;
  1910.                             int err;
  1911.                             zms = skipSpc(getnum2(zms, &oct, &err));
  1912.                             if (err) oct = 0;
  1913.                             note = *zms | 0x20;
  1914.                             if (note < 'a' || 'g' < note) {
  1915.                                 zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1916.                             }
  1917.                             zms = skipSpc(zms + 1);
  1918.                             note = 12 * (1 + oct) + ntbl[note - 'a'];
  1919.                             while (*zms == '+' || *zms == '#' || *zms == '-') {
  1920.                                 note += (*zms == '-') ? -1 : 1;
  1921.                                 zms = skipSpc(zms + 1);
  1922.                             }
  1923.                             zms = makeZmdCommonRegPcm(zms, trkdata, note, cominf->adpcmbank);
  1924.                         }
  1925.                         break;
  1926. #endif
  1927. /* FM/ADPCMsupport by Mamiya END) */
  1928.                 }
  1929.                 break;
  1930.             case '(':
  1931.                 {
  1932.                     char c;
  1933.  
  1934.                     zms = skipSpc(zms);
  1935.                     c  = *zms++;
  1936.                     switch(c) {
  1937.             /*OK*/        case 'i':    case 'I':                    /* (i) */
  1938.                             zms = initializeZMD(zms, trkdata, ")");
  1939.                             cominf->z_cmn_flag |= (1 << (0x00 / 4));
  1940.                             break;
  1941.                         case 'x':    case 'X':                    /* (X...) */
  1942.                             {
  1943.                                 const UBYTE f0f7 = 0,roland = 0;
  1944.                                 DWORD zmsskip;
  1945.                                 DWORD ifno = -1;    /*cominf->currentmidiout;*/
  1946.                                 char *cmnt = NULL;
  1947.  
  1948.                                 trkdata[0].zmd = exclusive(trkdata[0].zmd, zms,f0f7,&zmsskip,
  1949.                                                     ifno,cmnt,
  1950.                                                     roland,0,0,0,"","","), \t\x0d\x0a");
  1951.                                 zms += zmsskip;
  1952.                                 cominf->z_cmn_flag |= (1 << (0x34 / 4));
  1953.                             }
  1954.                             break;
  1955.                         case 'm':    case 'M':                    /* (M1,1000) */
  1956. /* no need to support */
  1957.                             {
  1958.                                 DWORD trk, bufsize;
  1959.                                 int err;
  1960.  
  1961.                                 /* zms = skipSpc(zms); */
  1962.                                 zms = getnum2(zms, &trk, &err);
  1963.                                 if (err) {
  1964.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1965.                                 }
  1966.  
  1967.                                 zms = skipchr(zms,", \t");
  1968.                                 zms = getnum2(zms, &bufsize,&err);
  1969.                                 if (err) {
  1970.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1971.                                 }
  1972.  
  1973.                                 zms = skiptochr(zms,")");
  1974.                                 zms++;
  1975.                                 trkdata[trk].buforgsize = bufsize;
  1976.                             }
  1977.                             break;
  1978.                         case 'b':    case 'B':                    /* (B0) (B1) */
  1979. /* no need to support?????? */
  1980.                             {
  1981.                                 int err;
  1982.                                 DWORD basech;
  1983.  
  1984.                                 zms = getnum2(zms,&basech,&err);
  1985.                                 if (err || (basech != 0 && basech != 1)) {
  1986.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  1987.                                 }
  1988.                                 cominf->basech = basech;
  1989.                                 zms = skiptochr(zms,")");
  1990.                                 zms++;
  1991.                             }
  1992.                             break;
  1993.             /*OK*/        case 'a':    case 'A':                    /*(Ach,tr) */
  1994.                             {
  1995.                                 zms = makeZmdAssign(zms,trkdata,cominf,&trks,1);
  1996. #ifdef A
  1997.                                 DWORD trk, ch, chtype;
  1998.                                 int i,err;
  1999.  
  2000.                                 zms = getDevice(zms,&ch, &chtype, cominf, 0);
  2001.                                 zms = skipchr(zms," ,\t");
  2002.                                 zms = getnum2(zms,&trk,&err);
  2003.                                 if (err) {
  2004.                                     zmserror("no track number is specified.",line,linebuf,zms,0,1);
  2005.                                 } else if (trk <= 0) {
  2006.                                     zmserror("illegal track number is specified.",line,linebuf,zms,0,1);
  2007.                                 }
  2008.                                 for (i = 0; i < trks; i++) {
  2009.                                     if (cominf->trkassign[i] == trk) {
  2010.                                         zmserror("The specified track# is already used.",line,linebuf,zms,0,1);
  2011.                                     }
  2012.                                 }
  2013.                                 trkdata[trk].ch = trkdata[trk].ch_ = ch;
  2014.                                 trkdata[trk].chtype = chtype;
  2015.                                 cominf->trkassign[trks++] = trk;
  2016.                                 cominf->trkassign[trks] = -1;
  2017.  
  2018.                                 zms = getAssign2(zms, trkdata, trk, ")");
  2019. /* fprintf(stderr,"[%d,%d]",trk,ch); */
  2020. #endif
  2021.                             }
  2022.                             break;
  2023.                         case 't':    case 'T':                    /* (T...) */
  2024.                             zms = makeZmdPlaytrk(zms,trkdata,&stat,&playtrk_start,1);
  2025. #ifdef A
  2026.                             stat = 1;
  2027.                             *trkdata[0].zmd++ = 0xFF;
  2028.                             if ((trkdata[0].zmd - trkdata[0].zmdbuf) & 1) {
  2029.                                 *trkdata[0].zmd++ = 0xFF;
  2030.                             }
  2031.                             while ( *zms != '(' ) {            /* '('まで戻す */
  2032.                                 zms--;
  2033.                             }
  2034.                             if (!playtrk_start) {
  2035.                                 playtrk_start = zms;
  2036.                             }
  2037.                             /*zms = skipLine(zms);*/    /* del v0.71 */
  2038. #endif
  2039.                             break;
  2040.             /*OK*/        case 'z':    case 'Z':
  2041.                             zms = setMasterClock(zms, ")",cominf);
  2042.                             break;
  2043.             /*OK*/        case 'o':    case 'O':                /* set tempo */
  2044.                             zms = setTempo(zms, ")",cominf);
  2045.                             break;
  2046.             /*OK*/        case 'd':    case 'D':
  2047.                             {
  2048.                                 int err;
  2049.                                 DWORD dbg;
  2050.  
  2051.                                 zms = getnum2(zms,&dbg,&err);
  2052.                                 if (err) {
  2053.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2054.                                 }
  2055.                                 cominf->debug = dbg;
  2056.                                 zms = skiptochr(zms,")");
  2057.                                 zms++;
  2058.                             }
  2059.                             break;
  2060.                         case 'f':    case 'F':
  2061.                         case 'p':    case 'P':
  2062.                         case 's':    case 'S':
  2063.                         case 'c':    case 'C':
  2064.                         case 'e':    case 'E':
  2065.                         case 'q':    case 'Q':
  2066.                         case 'r':    case 'R':
  2067. /* ignore: (Fn) (Pn1,n2,..) (Sn1,n2,...) (Cn1,n2,...) (Ech1,ch2,...) (Q) (R) */
  2068.                             zms = skiptochr(zms,")");
  2069.                             zms++;
  2070.                             break;
  2071. /* (BEGIN FM/ADPCMsupport by Mamiya */
  2072.                         case 'v':    case 'V':
  2073.                             {
  2074.                                 DWORD dat;
  2075.                                 int err, i;
  2076.                                 zms = getnum2(zms,&dat,&err);
  2077.                                 if (err < 0) {
  2078.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2079.                                 }
  2080.                                 *trkdata[0].zmd++ = 0x04;
  2081.                                 *trkdata[0].zmd++ = dat;
  2082.                                 zms = skipchr(zms," ,\t");
  2083.                                 zms = getnum2(zms,&dat,&err);
  2084.                                 if (err < 0 || dat != 0) {
  2085.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2086.                                 }
  2087.                                 for (i = 0 ; i < 55 ; i++) {
  2088.                                     zms = skipchr(zms," ,\t");
  2089.                                     zms = getnum2(zms,&dat,&err);
  2090.                                     if (err < 0) break;
  2091.                                     cominf->opmtone[i] = dat;
  2092.                                 }
  2093.                                 memcpy(trkdata[0].zmd, cominf->opmtone, 55);
  2094.                                 trkdata[0].zmd += 55;
  2095.                                 zms = skipSpcCr(zms);
  2096.                                 if (*zms != ')') {
  2097.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2098.                                 }
  2099.                                 zms++;
  2100.                             }
  2101.                             break;
  2102.                         case '@':
  2103.                             {
  2104.                                 DWORD dat;
  2105.                                 int err, i;
  2106.                                 zms = getnum2(zms,&dat,&err);
  2107.                                 if (err < 0) {
  2108.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2109.                                 }
  2110.                                 memcpy(cominf->opmtone + 55 - 9, default_fmtone + 55 - 9, 9);
  2111.                                 *trkdata[0].zmd++ = 0x1B;
  2112.                                 *trkdata[0].zmd++ = dat;
  2113.                                 for (i = 0 ; i < 55 ; i++) {
  2114.                                     zms = skipchr(zms," ,\t");
  2115.                                     zms = getnum2(zms,&dat,&err);
  2116.                                     if (err < 0) break;
  2117.                                     cominf->opmtone[i] = dat;
  2118.                                 }
  2119.                                 memcpy(trkdata[0].zmd, cominf->opmtone, 55);
  2120.                                 trkdata[0].zmd += 55;
  2121.                                 zms = skipSpcCr(zms);
  2122.                                 if (*zms != ')') {
  2123.                                     zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2124.                                 }
  2125.                                 zms++;
  2126.                             }
  2127.                             break;
  2128. /* FM/ADPCMsupport by Mamiya END) */
  2129.                         default:
  2130.                             zmserror("UNKNOWN MML",line,linebuf,zms,0,1);
  2131.                     }
  2132.                 }
  2133.                 break;
  2134.             default:
  2135.                 if (!playtrk_start && !mode) {
  2136.                     zms--;
  2137.                     if (*zms != ' ' && *zms != '\t' && *zms != 0x0d && *zms != 0x0a && *zms != 0x1A) {
  2138. /*
  2139.                         fprintf(stderr,"ERR! %.2X (%c)\n",*zms,*zms);
  2140. */
  2141.                         /*  omitted (AMIDI1,1)(T1)  */
  2142.                         makeZmdAssignMain(trkdata,cominf,1,&trks,0,0x8000);
  2143.                         stat = 1;
  2144.                         /* zmserror("SYNTAX ERROR",line,linebuf,zms,0,1); */
  2145.                     } else {
  2146.                         zms++;
  2147.                     }
  2148.                 } else {
  2149. /*fprintf(stderr,"[.1(%x)]",*(zms - 1));*/
  2150.                     if (*(zms - 1) != 0x1A) {
  2151. /*fprintf(stderr,"[!]");*/
  2152.                         zmserror("unknown MML.",line,linebuf,zms,2,1);
  2153.                         zms = skipLine(zms);
  2154.                     } else {
  2155. /*                        zms = skipLine(zms);
  2156.                         zmserror("dummy warning.",line,linebuf,zms,2,1);
  2157. */
  2158.                     }
  2159.                 }
  2160.                 break;
  2161.         }
  2162. /*
  2163.         if (stat) {
  2164.             break;
  2165.         }
  2166. */
  2167. /*fprintf(stderr,"(loopend)\n");*/
  2168.  
  2169.     }
  2170.     *zms2 = (playtrk_start)? playtrk_start : zms;
  2171.  
  2172.     trkdata[0].nowsize = (trkdata[0].zmdbuf[0] == 0xFF)?    /* no common data? */
  2173.         0 : trkdata[0].zmd - trkdata[0].zmdbuf;
  2174.     return trkdata;
  2175. }
  2176.  
  2177.  
  2178.  
  2179.  
  2180.  
  2181. /* ===========================================
  2182.      exclusive w/o any parameters(except ID,ifno)
  2183.    =========================================== */
  2184. UBYTE *macroExclusive0(UBYTE *zms, BYTE e[], const DWORD elen,
  2185.                         const char *cmnt,
  2186.                         int idflag, int roland, TRKCHINF *trkdata,
  2187.                         const BYTE target[])
  2188. {
  2189.     int err = 0;
  2190.     DWORD ID, ifno = 0xFF;
  2191.     UBYTE *zms_ = zms;
  2192.     int trk;
  2193.  
  2194.     for (trk = 0; target[trk] >= 0; trk++) {
  2195.         int err;
  2196.         int Trk = target[trk];
  2197.  
  2198.         if (idflag) {
  2199.             zms = getnum2(zms,&ID,&err);
  2200.             if (err == -1) {
  2201.                 ID = 0x10;
  2202.             } else if (err > 0) {
  2203.                 zmserror("exclusive ID error.",line,linebuf,zms,0,1);
  2204.             } else if (ID < 0) {
  2205.                 /* It is not to be error in V2, but.... */
  2206.             }
  2207.             e[2] = ID;
  2208.             zms = skipSpc(zms);
  2209.             if (*zms == ',') {
  2210.                 zms++;
  2211.             }
  2212.         }
  2213.         zms = getnum2(zms,&ifno,&err);
  2214.         if (err == -1) {
  2215.             ifno = 0xFF;
  2216.         } else if (err > 0) {
  2217.             zmserror("IF number error.",line,linebuf,zms,0,1);
  2218.         } else if (ID < 0) {
  2219.             /* It is not to be error in V2, but.... */
  2220.         } else {
  2221.             ifno--;        /* 1-4  ->  0-3 */
  2222.         }
  2223.  
  2224.         if (Trk) {
  2225.             *trkdata[Trk].zmd++ = 0xf4;
  2226.         } else {
  2227.             *trkdata[0].zmd++ = 0x34;
  2228.             *trkdata[0].zmd++ = ifno;            /* IF number: (-1 == current IF) */
  2229.         }
  2230.         *trkdata[Trk].zmd++ = strlen(cmnt);        /* comment length */
  2231.         strcpy(trkdata[Trk].zmd, cmnt);
  2232.         trkdata[Trk].zmd += strlen(cmnt);
  2233.         putDword(trkdata[Trk].zmd, elen + (roland? 2 : 1));    /* +2: checksum,0xf7 */
  2234.         trkdata[Trk].zmd += 4;
  2235.         trkdata[Trk].zmd = setex(trkdata[Trk].zmd, e, elen, roland);
  2236.         *trkdata[Trk].zmd++ = 0xf7;
  2237.     }
  2238.     return zms;
  2239. }
  2240.  
  2241.  
  2242. /* ===========================================
  2243.      exclusive w/ many parameters(except ID)
  2244.         ex_macro id {n1,n2,...}
  2245.      sorry the usage has a little difference
  2246.       from macroExclusive0
  2247.    =========================================== */
  2248. UBYTE *macroExclusiveN(UBYTE *zms, BYTE e[], const DWORD elen,const DWORD zmdlen,
  2249.                         const char *cmnt,
  2250.                         int idflag, int roland, const UBYTE mdl,const int warnlvl,
  2251.                         UBYTE *warn, TRKCHINF *trkdata)
  2252. {
  2253.     DWORD dev, ifno;
  2254.     int err = 0;
  2255.     const int f0f7 = 1;
  2256.     DWORD zmsskip;
  2257.     UBYTE *zmd_ = trkdata[0].zmd;
  2258.  
  2259.  
  2260.     if (idflag) {
  2261.         zms = getnum2(zms,&dev,&err);
  2262.         if (err == -1) {
  2263.             dev = 0x10;
  2264.         } else if (err > 0) {
  2265.             zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2266.         } else if (dev < 0) {
  2267.             /* It is not to be error in V2 */
  2268.         }
  2269.         zms = skipSpc(zms);
  2270.         if (*zms == ',') {
  2271.             zms++;
  2272.         }
  2273.     }
  2274.     zms = getnum2(zms,&ifno,&err);
  2275.     if (err == -1) {
  2276.         ifno = 0xFF;
  2277.     } else if (err > 0) {
  2278.         zmserror("IF number error.",line,linebuf,zms,0,1);
  2279.     } else if (err < 0) {
  2280.         /* It is not to be error in V2, but.... */
  2281.     }
  2282.  
  2283.  
  2284.     trkdata[0].zmd = exclusive(trkdata[0].zmd, zms, 
  2285.                                 f0f7, &zmsskip,ifno, cmnt, roland,dev,mdl,
  2286.                                 elen,e,
  2287.                                 "{","}, \t\x0d\x0a");
  2288.     zms += zmsskip;
  2289.     if (trkdata[0].zmd - zmd_ != zmdlen) {        /* non FULL parameters */
  2290.         zmserror(warn,line,linebuf,zms,warnlvl,1);
  2291.     }
  2292.  
  2293.     return zms;
  2294. }
  2295.  
  2296.  
  2297.  
  2298.  
  2299.  
  2300.  
  2301.  
  2302.  
  2303.  
  2304.  
  2305. UBYTE *getDevice(UBYTE *zms, DWORD *ch, DWORD *chtype, COMMONINF *cominf,
  2306.                     int allowALL)
  2307. {
  2308.     int err;
  2309.  
  2310.     zms = getnum2(zms,ch,&err);
  2311.     if (err > 0) {
  2312.         zmserror("illegal channel number is specified.",line,linebuf,zms,0,1);
  2313.     } else if (err < 0) {    /* (a????x,y) */
  2314.         int i,flg = -1;
  2315.         const char *base[4] = {"fm","adpcm","midi","all"};
  2316.         const int  bs[4]    = {0,8,9,-1};
  2317.         const int  chtp[] = {0, 1, 0x8000, -2};
  2318.  
  2319.         DWORD d, d2 = -1;
  2320.         int b = 0, err, err2 = -1;
  2321.         const int target = (allowALL)? 4 : 3;
  2322.  
  2323.         for (i = 0; i < target; i++) {
  2324.             if (!stricmp2(zms,base[i])) {
  2325.                 flg = i;
  2326.                 b = bs[flg];
  2327.                 *chtype = chtp[flg];
  2328.                 zms += strlen(base[i]);
  2329.                 break;
  2330.             }
  2331.         }
  2332.  
  2333.         zms = getnum2(zms,&d,&err);
  2334.         zms = skipSpc(zms);
  2335.         if (*zms == '-') {
  2336.             DWORD temp;
  2337.             const char *p[] = {"all",NULL};
  2338.  
  2339.             zms = getnum4(++zms,&d2,&err2,p, -1);
  2340.             temp = d2;        d2 = d;        d = temp;
  2341.             temp = err2;    err2 = err;    err = temp;
  2342.         }
  2343. /* fprintf(stderr,"err=%d, err2=%d flg=%d\n",err,err2,flg); */
  2344. /* fprintf(stderr,"d=%d, d2=%d ",d,d2); */
  2345.         if (err < 0) {
  2346.             if (flg != 1 && flg != 3) {        /* non (adpcm || all) && omit ch */
  2347.                 zmserror("illegal channel-strings is specified.",line,linebuf,zms,0,1);
  2348.             } else {
  2349. /* (BEGIN FM/ADPCMsupport by Mamiya */
  2350.                 if (cominf->polpcm++) {
  2351.                     *ch = 25 + cominf->polpcm - 2;
  2352.                 } else {
  2353. /* FM/ADPCMsupport by Mamiya END) */
  2354.                     if (flg == 1) {            /* adpcm */
  2355.                         *ch = 8;
  2356.                     } else if (flg == 3) {    /* ALL */
  2357.                         *ch = -2;
  2358.                     }
  2359.                 }
  2360.             }
  2361.         } else if (err > 0) {
  2362.             zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2363. /* (BEGIN FM/ADPCMsupport by Mamiya */
  2364.         } else if (flg == 1) {    /* adpcm */
  2365.             *ch = (d == 1) ? 8 : (25 + d - 2);
  2366. /* FM/ADPCMsupport by Mamiya END) */
  2367.         } else if (flg == 3) {    /* ALL */
  2368.             *ch = -2;
  2369.         } else {    /*(AxxxxN,m)*/
  2370.             if (err2 < 0) {                /* (AxxxxN,M) */
  2371. /* fprintf(stderr,"chtype1 = %d",*chtype); */
  2372.                 /* *ch = d + b - 1; */
  2373.                 *ch = d - 1;
  2374. /* fprintf(stderr,"CH= %d",*ch); */
  2375.                 if (flg == 2) {            /* (AMIDIn,m) */
  2376.                     *chtype = 0xFFFF;    /* current midi out */
  2377. /* fprintf(stderr,"chtype2 = %d",*chtype); */
  2378.                 } else if (flg == 1) {    /* (AADPCMx,y) */
  2379.                     if (*ch > 8) {        /* ADPCM2-16 */
  2380.                         *ch += 16;
  2381.                     }
  2382.                 }
  2383.             } else if (flg == 2) {        /* (AMIDIx-y,z */
  2384. /* fprintf(stderr,"chtype3 = %d, ch=%d, d2=%d ",*chtype, d-1, d2); */
  2385.                 /* *ch = d + b - 1; */
  2386.                 *ch = d - 1;
  2387.                 if (*ch < 0 || 16 <= *ch) {
  2388.                     zmserror("illegal channel number is specified. (must be in between 1 to 16)",line,linebuf,zms,0,1);
  2389.                 }
  2390. /*
  2391.                 if (d2 > 1) {
  2392.                     *ch += (d2 - 1) * 16 + 15;
  2393.                 }
  2394. */
  2395.                 *chtype += d2 - 1;
  2396. /* fprintf(stderr,"Ch= %d",*ch); */
  2397.             }
  2398.         }
  2399.     } else {        /* (ax,y) */
  2400.         (*ch)--;
  2401.         if (cominf->basech == 1) {
  2402. /* (BEGIN FM/ADPCMsupport by Mamiya */
  2403.             if (*ch < 16) {
  2404.                 *ch += 9;
  2405.             } else if (*ch < 16 + 9) {
  2406.                 *ch -= 16;
  2407.             }
  2408. /* FM/ADPCMsupport by Mamiya END) */
  2409.         }
  2410.         if (*ch < 8) {
  2411.             *chtype = 0;        /* FM */
  2412.         } else if (*ch == 8) {    /* ADPCM1 */
  2413.             *chtype = 1;
  2414.             *ch = 0;
  2415.         } else if (*ch < 25) {    /* MIDI */
  2416.             *chtype = 0xFFFF;
  2417.             *ch -= 9;
  2418.         } else if (*ch < 39) {    /* ADPCM2-16 */
  2419.             *chtype = 1;
  2420.             *ch = (*ch - 9) % 16;
  2421.         } else {                /* MIDI */
  2422.             *chtype = 0xFFFF;
  2423.         }
  2424.     }
  2425.  
  2426. /* fprintf(stderr,"[ch=%d chtype=%.4x]",*ch,*chtype); */
  2427.     return zms;
  2428. }
  2429.  
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435.  
  2436.  
  2437.  
  2438.  
  2439.  
  2440. UBYTE *setTempo(UBYTE *zms, char *endchar,COMMONINF *cominf)
  2441. {
  2442.     int err;
  2443.     DWORD tempo;
  2444.  
  2445.     zms = getnum2(zms,&tempo,&err);
  2446.     if (err) {
  2447.         zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2448.     }
  2449.     cominf->tempo = tempo;
  2450.     if (endchar) {
  2451.         zms = skiptochr(zms,endchar);
  2452.         zms++;
  2453.     }
  2454. /*
  2455.     *trkdata[0].zmd++ = 0x08;
  2456.     putWord(trkdata[0].zmd,tempo);
  2457.     trkdata[0].zmd += 2;
  2458. */
  2459.     return zms;
  2460. }
  2461.  
  2462.  
  2463.  
  2464. UBYTE *initializeZMD(UBYTE *zms, TRKCHINF *trkdata, const char *endchar)
  2465. {
  2466.     int err;
  2467.     DWORD num;
  2468.  
  2469.     zms = getnum2(zms,&num,&err);
  2470.     if (!err && num >= 3) {
  2471.         zmserror("V3-zms is not supported in zmc2.",line,linebuf,zms,3,1);
  2472.     }
  2473.     zms = skipSpc(zms);
  2474.  
  2475.     if (endchar && *zms++ != *endchar) {
  2476.         zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2477.     }
  2478.  
  2479.     *trkdata[0].zmd++ = 0x00;
  2480.     *trkdata[0].zmd++ = num;
  2481.  
  2482.     return zms;
  2483.  
  2484. }
  2485.  
  2486.  
  2487. UBYTE *setMasterClock(UBYTE *zms, const char *endchar,COMMONINF *cominf)
  2488. {
  2489.     int err;
  2490.     DWORD div;
  2491.  
  2492.     zms = getnum2(zms,&div,&err);
  2493.     if (err) {
  2494.         zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2495.     }
  2496.     cominf->div = div;
  2497.     if (endchar) {
  2498.         zms = skiptochr(zms,endchar);
  2499.         zms++;
  2500.     }
  2501.  
  2502.     /* cominf->z_cmn_flag |= (1 << (0x0c / 4)); */
  2503.  
  2504. /*
  2505.     *trkdata[0].zmd++ = 0x0c;
  2506.     putWord(trkdata[0].zmd,div);
  2507.     trkdata[0].zmd += 2;
  2508. */
  2509.  
  2510.     return zms;
  2511. }
  2512.  
  2513.  
  2514. UBYTE *getIfnoAndComment(UBYTE *zms, const char *endchar, DWORD *ifno, char **cmnt)
  2515. {
  2516.     int err;
  2517.  
  2518.     zms = skipSpc(zms);
  2519.     if (*zms == '=') {            /* legacy support */
  2520.         *ifno = -1;
  2521.         *cmnt = NULL;
  2522.         zms = skipSpc(zms + 1);
  2523.     } else if (*zms != ',') {
  2524.         zms = getnum2(zms,ifno,&err);
  2525.         if (err > 0) {
  2526.             zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2527.         } else if (err < 0) {
  2528.             *ifno = -1;
  2529.         }
  2530.     }
  2531.  
  2532.         zms = skipSpc(zms);
  2533.         if (*zms != ',') {
  2534.             *cmnt = NULL;
  2535.         } else {
  2536.             UBYTE *zms_;
  2537.             DWORD len;
  2538.  
  2539.             zms_ = zms = skipSpc(zms + 1);
  2540.             while (*zms != *endchar) {
  2541.                 zms++;
  2542.             }
  2543.             len = zms - zms_;
  2544.             *cmnt = (char*)emalloc(sizeof(char) * (len + 1),"cmnt_in_getIfnoAndComment");
  2545.             if (len) {
  2546.                 strncpy(*cmnt, zms_, len);
  2547.             }
  2548.             (*cmnt)[len] = '\0';
  2549.         }
  2550.  
  2551.     if (*zms != *endchar) {
  2552.         zmserror("SYNTAX ERROR",line,linebuf,zms,0,1);
  2553.     }
  2554.  
  2555.     return zms;
  2556. }
  2557.  
  2558.  
  2559.  
  2560.  
  2561.  
  2562.  
  2563. UBYTE *getAssign2(UBYTE *zms, TRKCHINF *trkdata,const int trk, const char *endchar)
  2564. {
  2565.     DWORD trkv = 128,trkf = 1,trks = 0,trkm = 0;
  2566.     char *cmnt;
  2567.     int err;
  2568.     const char *trksstr[] = {"play", "record", NULL};
  2569.     const char *trkmstr[] = {"normal", "rhythm", NULL};
  2570.  
  2571.     trkdata[trk].trkv = trkv;
  2572.     trkdata[trk].trkf = trkf;
  2573.     trkdata[trk].trks = trks;
  2574.     trkdata[trk].trkm = trkm;
  2575.     trkdata[trk].cmnt = NULL;
  2576.  
  2577.  
  2578.     zms = skipSpc(zms);
  2579.     if (*zms == *endchar) {
  2580.         zms++;
  2581.         return zms;
  2582.     } else if (*zms != ',') {
  2583.         return zms;
  2584.         /* zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1); */
  2585.     } else {
  2586.         zms = getnum2(++zms,&trkv,&err);
  2587.         if (err && *zms != ',') {
  2588.             zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1);
  2589.         } else {
  2590.             trkdata[trk].trkv = trkv;
  2591.         }
  2592.     }
  2593.  
  2594.     zms = skipSpc(zms);
  2595.     if (*zms == *endchar) {
  2596.         zms++;
  2597.         return zms;
  2598.     } else if (*zms != ',') {
  2599.         return zms;
  2600.         /* zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1); */
  2601.     } else {
  2602.         zms = getnum2(++zms,&trkf,&err);
  2603.         if (err && *zms != ',') {
  2604.             zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1);
  2605.         } else {
  2606.             trkdata[trk].trkf = trkf;
  2607.         }
  2608.     }
  2609.  
  2610.     zms = skipSpc(zms);
  2611.     if (*zms == *endchar) {
  2612.         zms++;
  2613.         return zms;
  2614.     } else if (*zms != ',') {
  2615.         return zms;
  2616.         /* zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1); */
  2617.     } else {
  2618.         zms = getnum4(++zms,&trks,&err,trksstr,0);
  2619.         if (err && *zms != ',') {
  2620.             zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1);
  2621.         } else {
  2622.             trkdata[trk].trks = trks;
  2623.         }
  2624.     }
  2625.  
  2626.     zms = skipSpc(zms);
  2627.     if (*zms == *endchar) {
  2628.         zms++;
  2629.         return zms;
  2630.     } else if (*zms != ',') {
  2631.         return zms;
  2632.         /* zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1); */
  2633.     } else {
  2634.         zms = getnum4(++zms,&trkm,&err,trkmstr,0);
  2635.         if (err && *zms != ',') {
  2636.             zmserror("SYNTAX ERROR.",line,linebuf,zms,0,1);
  2637.         } else {
  2638.             trkdata[trk].trkm = trkm;
  2639.         }
  2640.     }
  2641.  
  2642.     zms = skipSpc(zms);
  2643.     if (*zms == ',') {
  2644.         UBYTE *zms__ = ++zms;
  2645.         while (*zms != *endchar) {
  2646.             zms++;
  2647.         }
  2648.         cmnt = (char*)emalloc(sizeof(char) * (zms - zms__ + 1),"cmnt_in_getAssign2");
  2649.         if (zms - zms__) {
  2650.             strncpy(cmnt,zms__,zms - zms__);
  2651.         }
  2652.         cmnt[zms - zms__] = '\0';
  2653.     } else {
  2654.         cmnt = NULL;
  2655.     }
  2656. /*fprintf(stderr,"[%d: %s]",trk,cmnt); */
  2657. /*
  2658.     if (*zms != *endchar) {
  2659.         zmserror("`)' is unbraced.",line,linebuf,zms,0,1);
  2660.     }
  2661.     zms++;
  2662. */
  2663.     if (*zms == *endchar) {
  2664.         zms++;
  2665.     }
  2666.     trkdata[trk].cmnt = cmnt;
  2667. /*
  2668. fprintf(stderr,"ASSIGN:   trkv=%d trkf=%d trks=%d trkm=%d cmnt=%s\n",
  2669. trkv,trkf,trks,trkm,cmnt);
  2670. */
  2671.     return zms;
  2672. }
  2673.  
  2674.  
  2675.  
  2676.  
  2677.  
  2678. UBYTE *makeZmdAssign(UBYTE *zms,TRKCHINF *trkdata,
  2679.                         COMMONINF *cominf, BYTE *trks, const int mode)
  2680. {    /* mode: 0.. .assign 1.. (a) */
  2681.     DWORD trk, ch, chtype;
  2682.     int i, err;
  2683.     const char *endchar[2] = { "}", ")" };
  2684.  
  2685.     if (!mode) {    /* .assign */
  2686.         zms = skipSpc(zms);
  2687.         if (!stricmp2(zms,"tr")) {
  2688.             zms += 2;
  2689.         }
  2690.     } else {        /* (A) */
  2691.         zms = getDevice(zms,&ch, &chtype, cominf, 0);
  2692.         zms = skipchr(zms," ,\t");
  2693.     }
  2694.  
  2695.     zms = getnum2(zms,&trk,&err);
  2696.     if (err) {
  2697.         zmserror("no track number is specified.",line,linebuf,zms,0,1);
  2698.     } else if (trk <= 0) {
  2699.         zmserror("illegal track number is specified. (must be over than 0)",line,linebuf,zms,0,1);
  2700.     }
  2701.  
  2702.     for (i = 0; i < *trks; i++) {
  2703.         if (cominf->trkassign[i] == trk) {
  2704.             zmserror("The specified track# is already used.",line,linebuf,zms,0,1);
  2705.         }
  2706.     }
  2707.  
  2708.     if (!mode) {
  2709.         zms = skipSpcCr(zms);
  2710.         if (*zms == '{' || *zms == ',') {
  2711.             zms++;
  2712.         }
  2713.         zms = getDevice(zms,&ch, &chtype, cominf, 0);
  2714. /*
  2715.         zms = skiptochr(zms,"}");
  2716.         zms++;
  2717. */
  2718.     }
  2719.  
  2720.     makeZmdAssignMain(trkdata, cominf, trk, trks, ch, chtype);
  2721.  
  2722. /* fprintf(stderr,"[%d,%d]",trk,ch); */
  2723.     zms = getAssign2(zms, trkdata, trk, endchar[mode]);
  2724.  
  2725.     return zms;
  2726. }
  2727.  
  2728.  
  2729.  
  2730. void makeZmdAssignMain(TRKCHINF *trkdata,COMMONINF *cominf,
  2731.                         int trk, BYTE *trks, int ch, int chtype)
  2732. {
  2733.     trkdata[trk].ch = trkdata[trk].ch_ = ch;
  2734.     trkdata[trk].chtype = chtype;
  2735.     cominf->trkassign[(*trks)++] = trk;
  2736.     cominf->trkassign[*trks] = -1;
  2737.     initTrkInf0(trkdata, trk);
  2738.  
  2739. /*fprintf(stderr,"[%d: %d,%d,%x]",*trks,trk,ch,chtype);*/
  2740. }
  2741.  
  2742.  
  2743.  
  2744. UBYTE *makeZmdPlaytrk(UBYTE *zms,TRKCHINF *trkdata,
  2745.                         int *stat, UBYTE **playtrk_start, int mode)
  2746. {
  2747.     const char startchar[2] = { '.', '(' };
  2748.  
  2749.     *stat = 1;
  2750.     *trkdata[0].zmd++ = 0xFF;
  2751.     if ((trkdata[0].zmd - trkdata[0].zmdbuf) & 1) {
  2752.         *trkdata[0].zmd++ = 0xFF;
  2753.     }
  2754.     while ( *zms != startchar[mode] ) {        /* '('まで戻す */
  2755.         zms--;
  2756.     }
  2757.     if (!*playtrk_start) {
  2758.         *playtrk_start = zms;
  2759.     }
  2760.     /* zms = skipLine(zms); */    /* del v0.71 */
  2761.  
  2762.     return zms;
  2763. }
  2764.